* Moved Tests

+ Declare all new Types
This commit is contained in:
2022-05-07 14:11:24 +03:00
parent 97aa3e2281
commit 48a6d18c24
5 changed files with 42 additions and 4 deletions

View File

@@ -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 ] ##############################

View File

@@ -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
View 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
View 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
View 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"),
});
}