@mos-connection/model
Advanced tools
Comparing version 4.1.1-nightly-fix-main-not-updated-SOFIE-3067-20240412-081623-a155d24.0 to 4.1.1-nightly-master-20240430-072032-ffb8bf6.0
@@ -9,3 +9,3 @@ export interface IMOSTime { | ||
export declare function create(timestamp: AnyValue, strict: boolean): IMOSTime; | ||
export type AnyValue = Date | number | string | IMOSTime | undefined; | ||
export type AnyValue = Date | number | string | IMOSTime; | ||
export declare function validate(_mosDuration: IMOSTime, _strict: boolean): void; | ||
@@ -12,0 +12,0 @@ export declare function valueOf(mosTime: IMOSTime): number; |
@@ -10,49 +10,46 @@ "use strict"; | ||
let _timezoneOffset = 0; | ||
if (timestamp !== undefined) { | ||
// create date from time-string or timestamp number | ||
if (typeof timestamp === 'number') { | ||
if (timestamp === undefined) | ||
throw new Error(`MosTime: Invalid input: "${timestamp}"`); | ||
// create date from time-string or timestamp number | ||
if (typeof timestamp === 'number') { | ||
time = new Date(timestamp); | ||
} | ||
else if (typeof timestamp === 'string') { | ||
// formats: | ||
// YYYY-MM-DD'T'hh:mm:ss[,ddd]['Z'] | ||
// Sun Feb 25 2018 08:59:08 GMT+0100 (CET) | ||
// 2018-02-25T08:00:45.528Z | ||
let _timezoneZuluIndicator = ''; | ||
let _timezoneDeclaration = ''; | ||
// parse out custom Z indicator (mos-centric) | ||
const customFormatParseResult = parseMosCustomFormat(timestamp); | ||
// parse out custom timezones (mos local-local centric format) | ||
const timezoneParseResult = parseTimeOffset(timestamp); | ||
if (customFormatParseResult !== false) { | ||
_timezone = customFormatParseResult.timezoneIndicator; | ||
_timezoneOffset = customFormatParseResult.timezoneOffset; | ||
_timezoneZuluIndicator = customFormatParseResult.timezoneIndicator; | ||
const r = customFormatParseResult; | ||
const dateStr = `${r.yy}-${r.mm}-${r.dd}T${r.hh}:${r.ii}:${r.ss}${r.ms ? '.' + r.ms : ''}${_timezoneZuluIndicator}${_timezoneDeclaration}`; | ||
time = new Date(dateStr); | ||
} | ||
else if (timezoneParseResult !== false) { | ||
_timezoneDeclaration = timezoneParseResult.timezoneDeclaration; | ||
time = new Date(timestamp); | ||
} | ||
else if (typeof timestamp === 'string') { | ||
// formats: | ||
// YYYY-MM-DD'T'hh:mm:ss[,ddd]['Z'] | ||
// Sun Feb 25 2018 08:59:08 GMT+0100 (CET) | ||
// 2018-02-25T08:00:45.528Z | ||
let _timezoneZuluIndicator = ''; | ||
let _timezoneDeclaration = ''; | ||
// parse out custom Z indicator (mos-centric) | ||
const customFormatParseResult = parseMosCustomFormat(timestamp); | ||
// parse out custom timezones (mos local-local centric format) | ||
const timezoneParseResult = parseTimeOffset(timestamp); | ||
if (customFormatParseResult !== false) { | ||
_timezone = customFormatParseResult.timezoneIndicator; | ||
_timezoneOffset = customFormatParseResult.timezoneOffset; | ||
_timezoneZuluIndicator = customFormatParseResult.timezoneIndicator; | ||
const r = customFormatParseResult; | ||
const dateStr = `${r.yy}-${r.mm}-${r.dd}T${r.hh}:${r.ii}:${r.ss}${r.ms ? '.' + r.ms : ''}${_timezoneZuluIndicator}${_timezoneDeclaration}`; | ||
time = new Date(dateStr); | ||
} | ||
else if (timezoneParseResult !== false) { | ||
_timezoneDeclaration = timezoneParseResult.timezoneDeclaration; | ||
time = new Date(timestamp); | ||
} | ||
else { | ||
// try to parse the time directly with Date, for Date-supported formats | ||
time = new Date(timestamp); | ||
} | ||
else { | ||
// try to parse the time directly with Date, for Date-supported formats | ||
time = new Date(timestamp); | ||
} | ||
else if (typeof timestamp === 'object') { | ||
if (timestamp instanceof Date) { | ||
time = timestamp; | ||
} | ||
else if (timestamp?._mosTime !== undefined) { | ||
time = new Date(timestamp._mosTime); | ||
} | ||
else if (!strict) { | ||
time = new Date(); | ||
} | ||
else { | ||
throw new Error(`MosTime: Invalid input: "${timestamp}"`); | ||
} | ||
} | ||
else if (typeof timestamp === 'object') { | ||
if (timestamp instanceof Date) { | ||
time = timestamp; | ||
} | ||
else if (timestamp?._mosTime !== undefined) { | ||
time = new Date(timestamp._mosTime); | ||
} | ||
else if (!strict) { | ||
time = new Date(); | ||
} | ||
else { | ||
@@ -59,0 +56,0 @@ throw new Error(`MosTime: Invalid input: "${timestamp}"`); |
{ | ||
"name": "@mos-connection/model", | ||
"version": "4.1.1-nightly-fix-main-not-updated-SOFIE-3067-20240412-081623-a155d24.0", | ||
"version": "4.1.1-nightly-master-20240430-072032-ffb8bf6.0", | ||
"description": "Types and enums for the mos-connection library", | ||
@@ -44,3 +44,3 @@ "main": "dist/index.js", | ||
}, | ||
"gitHead": "38ec027871073e626f4740868ab3e2ce816ba608" | ||
"gitHead": "d90290af9b0a634f91e1596b15474653adae8c19" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59660
816