@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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@zelgadis87/utils-core",
4
- "version": "4.2.0",
4
+ "version": "4.2.1",
5
5
  "author": "Zelgadis87",
6
6
  "license": "ISC",
7
7
  "private": false,
@@ -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
  }