Skip to content

Commit fa4d0bb

Browse files
Add simple test to check returning period as time
1 parent 42bad63 commit fa4d0bb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

parser_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -1036,4 +1036,21 @@ func TestParser_Parse_customConfig(t *testing.T) {
10361036

10371037
dt, _ = parser.Parse(&cfg, "Понедельник")
10381038
assert.Equal(t, "ru", dt.Locale)
1039+
1040+
// Check returning period as time
1041+
cfg = dps.Configuration{
1042+
CurrentTime: tt(2024, 1, 1, 12, 0, 0),
1043+
ReturnTimeAsPeriod: true,
1044+
}
1045+
1046+
dt, _ = parser.Parse(&cfg, "in 10 minutes")
1047+
assert.Equal(t, tt(2024, 1, 1, 12, 10, 0), dt.Time)
1048+
assert.Equal(t, date.Minute, dt.Period)
1049+
assert.Equal(t, true, dt.Period.IsTime())
1050+
1051+
cfg.ReturnTimeAsPeriod = false
1052+
dt, _ = parser.Parse(&cfg, "in 10 minutes")
1053+
assert.Equal(t, tt(2024, 1, 1, 12, 10, 0), dt.Time)
1054+
assert.Equal(t, date.Day, dt.Period)
1055+
assert.Equal(t, false, dt.Period.IsTime())
10391056
}

0 commit comments

Comments
 (0)