@zelgadis87/utils-core 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/time/TimeInstant.ts +6 -0
package/package.json
CHANGED
package/src/time/TimeInstant.ts
CHANGED
|
@@ -272,6 +272,12 @@ export class TimeInstant extends TimeBase<TimeInstant> {
|
|
|
272
272
|
return TimeInstant.fromUnixTimestamp( new Date( str ).getTime() );
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
+
public static tryFromIso8601( str: string ) {
|
|
276
|
+
if ( !str.match( /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(Z|([+-]\d{2}:\d{2})))?$/ ) )
|
|
277
|
+
throw new Error( 'Invalid date given: ' + str );
|
|
278
|
+
return TimeInstant.fromUnixTimestamp( new Date( str ).getTime() );
|
|
279
|
+
}
|
|
280
|
+
|
|
275
281
|
public static now(): TimeInstant {
|
|
276
282
|
return TimeInstant.fromUnixTimestamp( Date.now() );
|
|
277
283
|
}
|