File tree 3 files changed +45
-11
lines changed
3 files changed +45
-11
lines changed Original file line number Diff line number Diff line change @@ -165,17 +165,19 @@ var fmap = map[string]interface{}{
165
165
"wkn" : Wkn ,
166
166
167
167
// time and dates
168
- "birthdate" : BirthDate ,
169
- "date_between" : DateBetween ,
170
- "dates_between" : DatesBetween ,
171
- "future" : Future ,
172
- "past" : Past ,
173
- "recent" : Recent ,
174
- "just_passed" : Justpassed ,
175
- "now_sub" : Nowsub ,
176
- "now_add" : Nowadd ,
177
- "soon" : Soon ,
178
- "unix_time_stamp" : UnixTimeStamp ,
168
+ "birthdate" : BirthDate ,
169
+ "date_between" : DateBetween ,
170
+ "dates_between" : DatesBetween ,
171
+ "future" : Future ,
172
+ "past" : Past ,
173
+ "recent" : Recent ,
174
+ "just_passed" : Justpassed ,
175
+ "format_timestamp" : FormatTimestamp ,
176
+ "now" : Now ,
177
+ "now_sub" : Nowsub ,
178
+ "now_add" : Nowadd ,
179
+ "soon" : Soon ,
180
+ "unix_time_stamp" : UnixTimeStamp ,
179
181
180
182
// phone
181
183
"country_code" : CountryCode ,
Original file line number Diff line number Diff line change @@ -664,6 +664,26 @@ var funcDesc = map[string]FunctionDescription{
664
664
Example : "jr template run --embedded '{{just_passed 60000}}'" ,
665
665
Output : "2024-11-10 22:59:5" ,
666
666
},
667
+ "now" : {
668
+ Name : "now" ,
669
+ Category : "time" ,
670
+ Description : "returns the current time as a Unix timestamp" ,
671
+ Parameters : "" ,
672
+ Localizable : false ,
673
+ Return : "int" ,
674
+ Example : "jr template run --embedded '{{now}}'" ,
675
+ Output : "2024-11-10 22:59:5" ,
676
+ },
677
+ "format_timestamp" : {
678
+ Name : "format_timestamp" ,
679
+ Category : "time" ,
680
+ Description : "formats the given timestamp with given pattern according to https://go.dev/src/time/format.go" ,
681
+ Parameters : "timestamp int64, format string" ,
682
+ Localizable : false ,
683
+ Return : "string" ,
684
+ Example : "jr template run --embedded '{{format_timestamp 1729857168 \" 2006-01-02 15:04:05.000000000\" }}'" ,
685
+ Output : "2024-11-10 22:59:5" ,
686
+ },
667
687
"key" : {
668
688
Name : "key" ,
669
689
Category : "utilities" ,
Original file line number Diff line number Diff line change @@ -74,6 +74,18 @@ func Justpassed(milliseconds int64) string {
74
74
return pastTime .Format (time .DateTime )
75
75
}
76
76
77
+ // Now returns the current time as a Unix millisecond timestamp
78
+ func Now () int64 {
79
+ return time .Now ().UnixMilli ()
80
+ }
81
+
82
+ // FormatTimestamp formats a unix millisecond timestamp with the given pattern
83
+ func FormatTimestamp (timestamp int64 , format string ) string {
84
+ t := time .Unix (0 , timestamp * int64 (time .Millisecond ))
85
+ formattedDate := t .Format (format )
86
+ return formattedDate
87
+ }
88
+
77
89
// Nowsub returns a date in the past of given milliseconds
78
90
func Nowsub (milliseconds int64 ) string {
79
91
now := time .Now ()
You can’t perform that action at this time.
0 commit comments