Skip to content

Commit

Permalink
chore: getting ready for calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasYOY committed Jul 9, 2023
1 parent a36a565 commit a0db1db
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ luac.out

.tests

Session.vim
71 changes: 71 additions & 0 deletions lua/obs/calendar.lua
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()

0 comments on commit a0db1db

Please sign in to comment.