diff options
Diffstat (limited to '.config/nvim/lua/leaf/calendar.lua')
| -rw-r--r-- | .config/nvim/lua/leaf/calendar.lua | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/.config/nvim/lua/leaf/calendar.lua b/.config/nvim/lua/leaf/calendar.lua new file mode 100644 index 0000000..f998785 --- /dev/null +++ b/.config/nvim/lua/leaf/calendar.lua @@ -0,0 +1,43 @@ +local M = {} + + +local floor = math.floor + + +M.MON = 1 +M.TUE = 2 +M.WED = 3 +M.THU = 4 +M.FRI = 5 +M.SAT = 6 +M.SUN = 7 + + +function M.calc_week_of_day(y, m, d) + -- Zeller's congruence + if m == 1 or m == 2 then + m = m + 12 + y = y - 1 + end + local C = floor(y / 100) + local Y = y % 100 + local G = 5*C + floor(C/4) + return 1 + (d + floor(26 * (m+1) / 10) + Y + floor(Y/4) + G + 5) % 7 +end + + +function M.translate_week_of_day(w, locale) + -- assert(locale == 'ja_JP') + return ({ + [M.MON] = '月', + [M.TUE] = '火', + [M.WED] = '水', + [M.THU] = '木', + [M.FRI] = '金', + [M.SAT] = '土', + [M.SUN] = '日', + })[w] +end + + +return M |
