Display ordinal indicators after date.

Forum rules
Before you post please read how to get help
User avatar
mzsade
Level 5
Level 5
Posts: 767
Joined: Sun Jul 19, 2009 4:36 am

Display ordinal indicators after date.

Postby mzsade » Mon Feb 20, 2017 3:21 am

Found this neat little script that i put to use in my conky.conf in lieu of the conky <time> variable.. Sorry if it's nothing new for most of you but i am impressed enough by it's elegant simplicity to risk adding more clutter to the forum. :wink:

Code: Select all

#!/bin/sh
DaySuffix() {
  case `date +%d` in
    1|21|31) echo "st";;
    2|22)    echo "nd";;
    3|23)    echo "rd";;
    *)       echo "th";;
  esac
}
date "+%a, %e`DaySuffix` %b, %Y"
Linux User #481272 Reg: 15th Sept., 2008

User avatar
mzsade
Level 5
Level 5
Posts: 767
Joined: Sun Jul 19, 2009 4:36 am

Re: Display ordinal indicators after date.

Postby mzsade » Fri Mar 03, 2017 1:34 am

The script had a bug, noticed it on the first of March when it began lisping. Fixed it,

Code: Select all

#!/bin/bash
Odin() {
  case `date +%d` in
    ?1|21|31) echo "st" ;;
    ?2|22)    echo "nd" ;;
    ?3|23)    echo "rd" ;;
    *)        echo "th" ;;
  esac
}
date "+%a, %e`Odin` %b, %Y"


Edit: My bad, the bug was still there, noticed it today when the script acquired a Russian accent, this one's totally bug free, Honest Injun!

Code: Select all

#!/bin/bash
Odin() {
  case `date +%d` in
    01|21|31) echo "st" ;;
    02|22)    echo "nd" ;;
    03|23)    echo "rd" ;;
    *)        echo "th" ;;
  esac
}
date "+%a, %e`Odin` %b, %Y"
Linux User #481272 Reg: 15th Sept., 2008


Return to “Compiz, Conky, Docks, & Widgets”