aboutsummaryrefslogtreecommitdiffhomepage
path: root/.config/nvim/lua/leaf/calendar.lua
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2021-11-19 15:57:09 +0900
committernsfisis <nsfisis@gmail.com>2022-01-29 17:37:40 +0900
commitf5986deda1ef0edf984b91792e44c72efbeececc (patch)
treeca43da3bd58d1349122a6e55ea9eb4b438d0c344 /.config/nvim/lua/leaf/calendar.lua
parent52062894a34a57d5c76b86f842befe5fd98a7773 (diff)
downloaddotfiles-f5986deda1ef0edf984b91792e44c72efbeececc.tar.gz
dotfiles-f5986deda1ef0edf984b91792e44c72efbeececc.tar.zst
dotfiles-f5986deda1ef0edf984b91792e44c72efbeececc.zip
neovim:leaf: add leaf plugin
Diffstat (limited to '.config/nvim/lua/leaf/calendar.lua')
-rw-r--r--.config/nvim/lua/leaf/calendar.lua43
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