-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,4 @@ luac.out | |
|
||
.tests | ||
|
||
Session.vim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
local popup = require "plenary.popup" | ||
|
||
local function get_date() | ||
return os.date "%x" | ||
end | ||
|
||
local function get_full_month_name() | ||
return os.date "%B" | ||
end | ||
|
||
local function get_full_year() | ||
return os.date "%Y" | ||
end | ||
|
||
local function get_full_weekday_name() | ||
return os.date "%A" | ||
end | ||
|
||
local function get_day() | ||
return os.date "%d" | ||
end | ||
|
||
local function get_days_in_month(month, year) | ||
local days_in_month = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } | ||
local d = days_in_month[month] | ||
|
||
-- check for leap year | ||
if month == 2 then | ||
if year % 4 == 0 then | ||
if year % 100 == 0 then | ||
if year % 400 == 0 then | ||
d = 29 | ||
end | ||
else | ||
d = 29 | ||
end | ||
end | ||
end | ||
return d | ||
end | ||
|
||
local function create_calendar() | ||
local width = 60 | ||
local height = 10 | ||
local borderchars = | ||
{ "─", "│", "─", "│", "╭", "╮", "╯", "╰" } | ||
local bufnr = vim.api.nvim_create_buf(false, false) | ||
|
||
local win_id, win = popup.create(bufnr, { | ||
title = "Obs.nvim Calendar", | ||
highlight = "ObsNvimCalendarWindow", | ||
line = math.floor(((vim.o.lines - height) / 2) - 1), | ||
col = math.floor((vim.o.columns - width) / 2), | ||
minwidth = width, | ||
minheight = height, | ||
borderchars = borderchars, | ||
}) | ||
|
||
vim.api.nvim_win_set_option( | ||
win.border.win_id, | ||
"winhl", | ||
"Normal:ObsNvimCalendarBorder" | ||
) | ||
|
||
return { | ||
bufnr = bufnr, | ||
win_id = win_id, | ||
} | ||
end | ||
|
||
create_calendar() |