+ Seconds Handler
This commit is contained in:
parent
5b71124dde
commit
04dc772e05
|
@ -35,7 +35,7 @@ const secondtypes = [ "s" ];
|
||||||
/**
|
/**
|
||||||
* Possible formats for the date
|
* Possible formats for the date
|
||||||
*/
|
*/
|
||||||
export type secondType = (typeof secondtypes)[number];
|
export type secondType = "s";
|
||||||
export const isSecondType = (x: any): x is secondType => secondtypes.includes(x);
|
export const isSecondType = (x: any): x is secondType => secondtypes.includes(x);
|
||||||
|
|
||||||
|
|
||||||
|
|
16
src/index.ts
16
src/index.ts
|
@ -1,6 +1,6 @@
|
||||||
import { dayDictionary } from "./Dictionaries/dateDictionary";
|
import { dayDictionary } from "./Dictionaries/dateDictionary";
|
||||||
import { monthDictionary } from "./Dictionaries/monthDictionary";
|
import { monthDictionary } from "./Dictionaries/monthDictionary";
|
||||||
import { commonDateFormats, dateType, hourType, isDateType, isHourType, isMeridiemType, isMinuteType, isMonthType, isYearType, meridiemType, minuteType, monthType, yearType } from "./Types/formatTypes";
|
import { commonDateFormats, dateType, hourType, isDateType, isHourType, isMeridiemType, isMinuteType, isMonthType, isSecondType, isYearType, meridiemType, minuteType, monthType, secondType, yearType } from "./Types/formatTypes";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,6 +70,8 @@ export default class TymeJS {
|
||||||
formattedDate += this.getHour(char);
|
formattedDate += this.getHour(char);
|
||||||
else if ( isMinuteType(char) )
|
else if ( isMinuteType(char) )
|
||||||
formattedDate += this.getMinutes(char);
|
formattedDate += this.getMinutes(char);
|
||||||
|
else if ( isSecondType(char) )
|
||||||
|
formattedDate += this.getSeconds(char);
|
||||||
else {
|
else {
|
||||||
// Just append the char to the result
|
// Just append the char to the result
|
||||||
formattedDate += char;
|
formattedDate += char;
|
||||||
|
@ -115,7 +117,7 @@ export default class TymeJS {
|
||||||
return String(h).padStart(2, "0");
|
return String(h).padStart(2, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(`Invalid format for Hour ${t}`);
|
throw new Error(`Invalid format for Hours ${t}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getMinutes(t: minuteType ): string {
|
public getMinutes(t: minuteType ): string {
|
||||||
|
@ -124,7 +126,15 @@ export default class TymeJS {
|
||||||
return String(this.ts.getMinutes()).padStart(2, "0");
|
return String(this.ts.getMinutes()).padStart(2, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(`Invalid format for Minute ${t}`);
|
throw new Error(`Invalid format for Minutes ${t}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getSeconds(t: secondType) {
|
||||||
|
if ( t === "s" ) {
|
||||||
|
return String(this.ts.getSeconds()).padStart(2, "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error(`Invalid format for Seconds ${t}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue