@@ -65,6 +65,14 @@ type ISO8601 time.Time
65
65
var _ Exampler = (* ISO8601 )(nil )
66
66
67
67
// ParseISO8601 reads from "s" and returns the ISO8601 time.
68
+ //
69
+ // The function supports the following formats:
70
+ // - 2024-01-02T15:04:05.999999Z
71
+ // - 2024-01-02T15:04:05+07:00
72
+ // - 2024-04-08T08:05:04.830140+00:00
73
+ // - 2024-01-02T15:04:05Z
74
+ // - 2024-04-08T08:05:04.830140
75
+ // - 2024-01-02T15:04:05
68
76
func ParseISO8601 (s string ) (ISO8601 , error ) {
69
77
if s == "" || s == "null" {
70
78
return ISO8601 {}, nil
@@ -216,10 +224,12 @@ func (t ISO8601) MarshalJSON() ([]byte, error) {
216
224
// Examples returns a list of example values.
217
225
func (t ISO8601 ) ListExamples () any {
218
226
return []string {
219
- "2006-01-02T15:04:05" ,
220
- "2022-08-09T00:00:00.000000" ,
221
- "2022-08-10T03:21:00.000000+03:00" ,
222
- "2023-02-04T09:48:14+00:00" ,
227
+ "2024-01-02T15:04:05.999999Z" ,
228
+ "2024-01-02T15:04:05+07:00" ,
229
+ "2024-04-08T08:05:04.830140+00:00" ,
230
+ "2024-01-02T15:04:05Z" ,
231
+ "2024-04-08T08:05:04.830140" ,
232
+ "2024-01-02T15:04:05" ,
223
233
}
224
234
}
225
235
@@ -235,6 +245,26 @@ func (t ISO8601) IsZero() bool {
235
245
return time .Time (t ).IsZero ()
236
246
}
237
247
248
+ // After reports whether the time instant "t" is after "u".
249
+ func (t ISO8601 ) After (u ISO8601 ) bool {
250
+ return t .ToTime ().After (u .ToTime ())
251
+ }
252
+
253
+ // Equal reports whether the time instant "t" is equal to "u".
254
+ func (t ISO8601 ) Equal (u ISO8601 ) bool {
255
+ return t .ToTime ().Equal (u .ToTime ())
256
+ }
257
+
258
+ // Add returns the time "t" with the duration added.
259
+ func (t ISO8601 ) Add (d time.Duration ) ISO8601 {
260
+ return ISO8601 (t .ToTime ().Add (d ))
261
+ }
262
+
263
+ // Sub returns the duration between "t" and "u".
264
+ func (t ISO8601 ) Sub (u ISO8601 ) time.Duration {
265
+ return t .ToTime ().Sub (u .ToTime ())
266
+ }
267
+
238
268
// String returns the text representation of the "t" using the ISO8601 time layout.
239
269
func (t ISO8601 ) String () string {
240
270
tt := t .ToTime ()
0 commit comments