From 48a6d18c244d5ddd7ef63d2d61e0db2adbab846d Mon Sep 17 00:00:00 2001 From: Kato Twofold Date: Sat, 7 May 2022 14:11:24 +0300 Subject: [PATCH] * Moved Tests + Declare all new Types --- src/Types/formatTypes.ts | 32 +++++++++++++++++++++++++++++++ src/index.ts | 8 +++++++- {tests => src/tests}/dateTest.ts | 2 +- {tests => src/tests}/fullTest.ts | 2 +- {tests => src/tests}/monthTest.ts | 2 +- 5 files changed, 42 insertions(+), 4 deletions(-) rename {tests => src/tests}/dateTest.ts (91%) rename {tests => src/tests}/fullTest.ts (85%) rename {tests => src/tests}/monthTest.ts (91%) diff --git a/src/Types/formatTypes.ts b/src/Types/formatTypes.ts index 5f79410..fecfe0e 100644 --- a/src/Types/formatTypes.ts +++ b/src/Types/formatTypes.ts @@ -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 ] ############################## diff --git a/src/index.ts b/src/index.ts index 04713ea..4b8d11b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 ] ############################## diff --git a/tests/dateTest.ts b/src/tests/dateTest.ts similarity index 91% rename from tests/dateTest.ts rename to src/tests/dateTest.ts index cdac4b6..8281427 100644 --- a/tests/dateTest.ts +++ b/src/tests/dateTest.ts @@ -1,4 +1,4 @@ -import TymeJS from "../src"; +import TymeJS from ".."; let d: Date = new Date(); diff --git a/tests/fullTest.ts b/src/tests/fullTest.ts similarity index 85% rename from tests/fullTest.ts rename to src/tests/fullTest.ts index 2ee48a8..7b1d7dd 100644 --- a/tests/fullTest.ts +++ b/src/tests/fullTest.ts @@ -1,4 +1,4 @@ -import TymeJS from "../src"; +import TymeJS from ".."; const a = new TymeJS(); diff --git a/tests/monthTest.ts b/src/tests/monthTest.ts similarity index 91% rename from tests/monthTest.ts rename to src/tests/monthTest.ts index 8e63352..6057e0f 100644 --- a/tests/monthTest.ts +++ b/src/tests/monthTest.ts @@ -1,4 +1,4 @@ -import TymeJS from "../src"; +import TymeJS from ".."; for ( let i = 0; i < 12; i++ ) {