* Moved Tests
+ Declare all new Types
This commit is contained in:
@@ -6,6 +6,38 @@ export type commonDateFormats = "d/m/Y" | "m/d/Y" | "d/m/Y h:i A" | "d/m/Y H:i"
|
||||
|
||||
// ############################## [ Time Formats ] ##############################
|
||||
|
||||
// =-=-=-=-=-=-=-=-=-=-= [ Meridiem ] =-=-=-=-=-=-=-=-=-=-=
|
||||
const mertypes = [ "a", "A" ];
|
||||
/**
|
||||
* Possible formats for the date
|
||||
*/
|
||||
export type meridiemType = (typeof mertypes)[number];
|
||||
export const isMeridiemType = (x: any): x is meridiemType => mertypes.includes(x);
|
||||
|
||||
// =-=-=-=-=-=-=-=-=-=-= [ Hours ] =-=-=-=-=-=-=-=-=-=-=
|
||||
const hourtypes = [ "g", "G", "h", "H" ];
|
||||
/**
|
||||
* Possible formats for the date
|
||||
*/
|
||||
export type hourType = (typeof hourtypes)[number];
|
||||
export const isHourType = (x: any): x is hourType => hourtypes.includes(x);
|
||||
|
||||
// =-=-=-=-=-=-=-=-=-=-= [ Minutes ] =-=-=-=-=-=-=-=-=-=-=
|
||||
const minutetypes = [ "g", "G", "h", "H" ];
|
||||
/**
|
||||
* Possible formats for the date
|
||||
*/
|
||||
export type minuteType = (typeof minutetypes)[number];
|
||||
export const isMinuteType = (x: any): x is minuteType => minutetypes.includes(x);
|
||||
|
||||
// =-=-=-=-=-=-=-=-=-=-= [ Seconds ] =-=-=-=-=-=-=-=-=-=-=
|
||||
const secondtypes = [ "g", "G", "h", "H" ];
|
||||
/**
|
||||
* Possible formats for the date
|
||||
*/
|
||||
export type secondType = (typeof secondtypes)[number];
|
||||
export const isSecondType = (x: any): x is secondType => secondtypes.includes(x);
|
||||
|
||||
|
||||
|
||||
// ############################## [ Date Formats ] ##############################
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { dayDictionary } from "./Dictionaries/dateDictionary";
|
||||
import { monthDictionary } from "./Dictionaries/monthDictionary";
|
||||
import { commonDateFormats, dateType, isDateType, isMonthType, isYearType, monthType, yearType } from "./Types/formatTypes";
|
||||
import { commonDateFormats, dateType, isDateType, isMonthType, isYearType, meridiemType, monthType, yearType } from "./Types/formatTypes";
|
||||
|
||||
|
||||
/**
|
||||
@@ -74,6 +74,12 @@ export default class TymeJS {
|
||||
|
||||
// ############################## [ Time Formats ] ##############################
|
||||
|
||||
public getMeridiem(t: meridiemType): string {
|
||||
|
||||
|
||||
throw new Error(`Invalid format for meridiem ${t}`);
|
||||
}
|
||||
|
||||
|
||||
// ############################## [ Date Formats ] ##############################
|
||||
|
||||
|
||||
18
src/tests/dateTest.ts
Normal file
18
src/tests/dateTest.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import TymeJS from "..";
|
||||
|
||||
let d: Date = new Date();
|
||||
|
||||
for ( let i = 0; i < 7; i++ ) {
|
||||
|
||||
const a = new TymeJS(d);
|
||||
console.log(d, {
|
||||
single: a.getDate("j"),
|
||||
double: a.getDate("d"),
|
||||
dowdouble: a.getDate("w"),
|
||||
full: a.getDate("l"),
|
||||
short: a.getDate("D"),
|
||||
});
|
||||
|
||||
d.setDate(d.getDate() + 1);
|
||||
}
|
||||
|
||||
9
src/tests/fullTest.ts
Normal file
9
src/tests/fullTest.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import TymeJS from "..";
|
||||
|
||||
const a = new TymeJS();
|
||||
|
||||
console.log(a.format("d/m/Y"));
|
||||
console.log(a.format("d/m/Y h:i A"));
|
||||
console.log(a.format("Y-m-d"));
|
||||
console.log(a.format("Y-m-d H:i:s"));
|
||||
|
||||
17
src/tests/monthTest.ts
Normal file
17
src/tests/monthTest.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import TymeJS from "..";
|
||||
|
||||
for ( let i = 0; i < 12; i++ ) {
|
||||
|
||||
let currentMonth: Date = new Date();
|
||||
currentMonth.setMonth(i)
|
||||
|
||||
const a = new TymeJS(currentMonth);
|
||||
|
||||
console.log({
|
||||
single: a.getMonth("n"),
|
||||
double: a.getMonth("m"),
|
||||
full: a.getMonth("F"),
|
||||
short: a.getMonth("M"),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user