Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: take DST into account in augend.date["%H:%M"] #74

Merged
merged 1 commit into from Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lua/dial/augend/date.lua
Expand Up @@ -461,6 +461,7 @@ function DateFormat:find(line, cursor)
local now = os.date("*t", os.time()) --[[@as osdate]]
dt_info.month = now.month
dt_info.year = now.year
dt_info.isdst = now.isdst
end

local datekind = self.default_kind
Expand Down
44 changes: 42 additions & 2 deletions run
@@ -1,16 +1,56 @@
#!/usr/bin/env bash

TESTS_INIT=tests/minimal_init.lua
TESTS_DIR=tests/
TESTS_DIR=tests

function _test_tz {
# DST always in effect
echo "Checking with $1 time zone (DST always enable)"
TZ=$1
export TZ
nvim \
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "PlenaryBustedDirectory ${TESTS_DIR}/dial/augend/date_spec.lua \
{ minimal_init = '${TESTS_INIT}' }"
}

function test {

# Force TimeZone to ensure consistent behavior of os.date regarding Daylight
# Saving Time

# Standard case (No DST)
# Full test case
TZ='GMT+0'
export TZ
nvim \
--headless \
--noplugin \
-u ${TESTS_INIT} \
-c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${TESTS_INIT}' }"
-c "PlenaryBustedDirectory ${TESTS_DIR} \
{ minimal_init = '${TESTS_INIT}' }" ||
return 1

# permanent DST: os.date always returns `isdst == false`
_test_tz "Asia/Tokyo" || return 1

# Check standard DST. Since the date is not controlled, we might have
# periods of time without any timezone with `isdst == true`.
# Therefore, select timezones that overlap so that DST is actually
# tested.

# DST in Northern hemisphere
# Start: Second Sunday in March at 2:00
# End: First Sunday in November at 2:00
_test_tz "America/New_York" || return 1

# DST in Southern hemisphere
# Start: First Sunday in October at 2:00
# End: First Sunday in April at 3:00
_test_tz "Australia/Sidney" || return 1

}


Expand Down
16 changes: 16 additions & 0 deletions tests/dial/augend/date_spec.lua
Expand Up @@ -158,6 +158,22 @@ describe([[Test of date with format "%Y年%-m月%-d日(%ja)":]], function()
end)
end)

describe([[Test of date with format %H:%M:]], function()
local augend = date.alias["%H:%M"]
describe("find function", function()
it("can find dates in a given format with Time Zones", function()
assert.are.same(augend:find_stateful("date: 11:50", 1), { from = 7, to = 11 })
assert.are.same(augend.kind, "min")
assert.are.same(augend:find_stateful("date: 11:50", 6), { from = 7, to = 11 })
assert.are.same(augend.kind, "min")
assert.are.same(augend:find_stateful("date: 11:50", 7), { from = 7, to = 11 })
assert.are.same(augend.kind, "hour")
assert.are.same(augend:find_stateful("date: 11:50", 10), { from = 7, to = 11 })
assert.are.same(augend.kind, "min")
end)
end)
end)

describe([[Test of clamp & end_sensitive option:]], function()
describe("{clamp = false and end_sensitive = false}", function()
local augend = date.new {
Expand Down