diff options
author | Aki <please@ignore.pl> | 2023-08-31 23:22:45 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-08-31 23:22:45 +0200 |
commit | 1e81f505fc56efba701ba62a6d858d5fb5b70a7f (patch) | |
tree | 50b1b181b945082f3745ec43f8c7c0bf29cb2af8 /spec/dates_spec.lua | |
parent | fb1297a0cd84fde95c565178d0d223258d1c2bee (diff) | |
download | activity-1e81f505fc56efba701ba62a6d858d5fb5b70a7f.zip activity-1e81f505fc56efba701ba62a6d858d5fb5b70a7f.tar.gz activity-1e81f505fc56efba701ba62a6d858d5fb5b70a7f.tar.bz2 |
Split out dates module
Diffstat (limited to 'spec/dates_spec.lua')
-rw-r--r-- | spec/dates_spec.lua | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/dates_spec.lua b/spec/dates_spec.lua new file mode 100644 index 0000000..6239fdc --- /dev/null +++ b/spec/dates_spec.lua @@ -0,0 +1,43 @@ +local dates = require "activity.dates" + +describe("Days in a year", function() + it("should support regular years", function() + assert.are.equal(365, dates.days_in(1970)) + assert.are.equal(365, dates.days_in(2001)) + end) + + it("should support lean years", function() + assert.are.equal(366, dates.days_in(2004)) + assert.are.equal(366, dates.days_in(1980)) + end) + + it("should support *00 years", function() + assert.are.equal(366, dates.days_in(2000)) + assert.are.equal(365, dates.days_in(2100)) + assert.are.equal(365, dates.days_in(2200)) + assert.are.equal(365, dates.days_in(2300)) + assert.are.equal(366, dates.days_in(2400)) + end) +end) + +describe("This year is", function() + local this_year = os.date "%Y" -- Quite useless test + + it(tostring(this_year), function() + assert.are.equal(this_year, dates.this_year()) + end) +end) + +describe("First week day of", function() + it("2023 is Sunday", function() + assert.are.equal(1, dates.first_week_day(2023)) + end) + + it("2022 is Saturday", function() + assert.are.equal(7, dates.first_week_day(2022)) + end) + + it("2020 is Saturday", function() + assert.are.equal(4, dates.first_week_day(2020)) + end) +end) |