Skip to content

Commit

Permalink
lib: add more time layouts from std
Browse files Browse the repository at this point in the history
  • Loading branch information
efd6 committed May 8, 2024
1 parent 0f8a173 commit 54e165d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ import (
// "StampMilli": time.StampMilli,
// "StampMicro": time.StampMicro,
// "StampNano": time.StampNano,
// "HTTP": http.TimeFormat
// "HTTP": http.TimeFormat,
// "DateOnly": time.DateOnly,
// "DateTime": time.DateTime,
// "TimeOnly": time.TimeOnly
// }
func Time() cel.EnvOption {
return cel.Lib(timeLib{})
Expand Down Expand Up @@ -168,6 +171,10 @@ func (timeLib) ProgramOptions() []cel.ProgramOption {
"StampMicro": time.StampMicro,
"StampNano": time.StampNano,
"HTTP": http.TimeFormat,
// TODO: Use the constants from time when go1.19 support is dropped.
"DateTime": "2006-01-02 15:04:05", // time.DateTime from future
"DateOnly": "2006-01-02", // time.DateOnly from future
"TimeOnly": "15:04:05", // time.TimeOnly from future
},
}),
cel.Functions(
Expand Down
3 changes: 3 additions & 0 deletions testdata/time_layout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ time_layout
-- want.txt --
{
"ANSIC": "Mon Jan _2 15:04:05 2006",
"DateOnly": "2006-01-02",
"DateTime": "2006-01-02 15:04:05",
"HTTP": "Mon, 02 Jan 2006 15:04:05 GMT",
"Kitchen": "3:04PM",
"Layout": "01/02 03:04:05PM '06 -0700",
Expand All @@ -22,5 +24,6 @@ time_layout
"StampMicro": "Jan _2 15:04:05.000000",
"StampMilli": "Jan _2 15:04:05.000",
"StampNano": "Jan _2 15:04:05.000000000",
"TimeOnly": "15:04:05",
"UnixDate": "Mon Jan _2 15:04:05 MST 2006"
}

0 comments on commit 54e165d

Please sign in to comment.