mirror of
https://github.com/marcogll/passkit-generator.git
synced 2026-03-15 13:25:19 +00:00
Removed dateToW3Cstring function
This commit is contained in:
28
src/utils.ts
28
src/utils.ts
@@ -2,40 +2,16 @@ import * as Messages from "./messages";
|
||||
import type Bundle from "./Bundle";
|
||||
|
||||
/**
|
||||
* Acts as a wrapper for converting date to W3C string
|
||||
* Converts a date to W3C / UTC string
|
||||
* @param date
|
||||
* @returns
|
||||
*/
|
||||
|
||||
export function processDate(date: Date): string | undefined {
|
||||
if (!(date instanceof Date)) {
|
||||
if (!(date instanceof Date) || Number.isNaN(Number(date))) {
|
||||
throw "Invalid date";
|
||||
}
|
||||
|
||||
const dateParse = dateToW3CString(date);
|
||||
|
||||
if (!dateParse) {
|
||||
throw "Invalid date";
|
||||
}
|
||||
|
||||
return dateParse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a date to W3C Standard format
|
||||
*
|
||||
* @function dateToW3Cstring
|
||||
* @params date - The date to be parsed
|
||||
* @returns - The parsed string if the parameter is valid,
|
||||
* undefined otherwise
|
||||
*/
|
||||
|
||||
function dateToW3CString(date: Date) {
|
||||
// if it is NaN, it is "Invalid Date"
|
||||
if (isNaN(Number(date))) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://www.w3.org/TR/NOTE-datetime
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user