aboutsummaryrefslogtreecommitdiff
path: root/.config/luastatus-scripts-dwm/time-date.lua
blob: 8fce7a1d0a2c05e7eadcfedd16af3d7548104dd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
months = {'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'}
wday = {'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'}
widget = {
    plugin = 'timer',
    cb = function()
        local d = os.date('*t')

        if d.hour < 12 then
          suffix = "a.m."
        else
          suffix = "p.m."
          d.hour = d.hour - 12
        end

        local date_suffix = "th"
        if not (d.day % 100 >= 11 and d.day % 100 <= 13) then
          local last_digit = d.day % 10
          if last_digit == 1 then
            date_suffix = "st"
          elseif last_digit == 2 then
            date_suffix = "nd"
          elseif last_digit == 3 then
            date_suffix = "rd"
          end
        end

        local time_icon = ""
        if d.hour == 0 or d.hour == 12 then
          time_icon = "󱑖"
        elseif d.hour == 1 then
          time_icon = "󱑋"
        elseif d.hour == 2 then
          time_icon = "󱑌"
        elseif d.hour == 3 then
          time_icon = "󱑍"
        elseif d.hour == 4 then
          time_icon = "󱑎"
        elseif d.hour == 5 then
          time_icon = "󱑏"
        elseif d.hour == 6 then
          time_icon = "󱑐"
        elseif d.hour == 7 then
          time_icon = "󱑑"
        elseif d.hour == 8 then
          time_icon = "󱑒"
        elseif d.hour == 9 then
          time_icon = "󱑓"
        elseif d.hour == 10 then
          time_icon = "󱑔"
        elseif d.hour == 11 then
          time_icon = "󱑕"
        end

        return {
            string.format('󰃭 %d%s %s %d (%s)    %s  %d:%02d %s   ', d.day, date_suffix, months[d.month], d.year, wday[d.wday], time_icon, d.hour, d.min, suffix),
        }
    end,
}