Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/time.carp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,31 @@
(Result.Error _) -2)
"strptime %I %p parses 12 PM as 12")

(assert-equal test
-1
(match (Datetime.strptime "PM 2024-03-15" "%p %Y-%m-%d")
(Result.Success dt) (Maybe.from @(Datetime.hours &dt) -1)
(Result.Error _) -2)
"strptime %p with no hour specifier leaves the hour unset (PM)")
(assert-equal test
-1
(match (Datetime.strptime "AM 2024-03-15" "%p %Y-%m-%d")
(Result.Success dt) (Maybe.from @(Datetime.hours &dt) -1)
(Result.Error _) -2)
"strptime %p with no hour specifier leaves the hour unset (AM)")
(assert-equal test
15
(match (Datetime.strptime "03 PM 2024-03-15" "%I %p %Y-%m-%d")
(Result.Success dt) (Maybe.from @(Datetime.hours &dt) -1)
(Result.Error _) -2)
"strptime %I %p parses 03 PM as 15")
(assert-equal test
7
(match (Datetime.strptime "07 2024-03-15" "%H %Y-%m-%d")
(Result.Success dt) (Maybe.from @(Datetime.hours &dt) -1)
(Result.Error _) -2)
"strptime %H parses the hour with no am/pm marker")

(assert-equal test
123456789
(match (Datetime.strptime "14:30:00.123456789" "%H:%M:%S.%n")
Expand Down
1 change: 1 addition & 0 deletions time.carp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,7 @@ Example:
(Result.Error e) (Result.Error e)
(Result.Success d)
(let [final-hr (cond
(= hr -1) hr
(= ampm 2) (if (< hr 12) (+ hr 12) hr)
(= ampm 1) (if (= hr 12) 0 hr)
hr)
Expand Down