diff --git a/package.json b/package.json index 3fd739d..d3e1144 100644 --- a/package.json +++ b/package.json @@ -14,5 +14,8 @@ "format" ], "author": "Kato Twofold", - "license": "MIT" + "license": "MIT", + "repository": { + "url": "https://github.com/JustKato/Tyme.js" + } } diff --git a/src/Dictionaries/dateDictionary.ts b/src/Dictionaries/dateDictionary.ts new file mode 100644 index 0000000..ba69170 --- /dev/null +++ b/src/Dictionaries/dateDictionary.ts @@ -0,0 +1,17 @@ +/** + * A dictionary for all of the days of the week + */ + const dayDictionary: Array = [ + "Sunday", + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", +]; + + +export { + dayDictionary +}; \ No newline at end of file diff --git a/src/Types/formatTypes.ts b/src/Types/formatTypes.ts index 785ee5e..3739297 100644 --- a/src/Types/formatTypes.ts +++ b/src/Types/formatTypes.ts @@ -1 +1,2 @@ -export type monthType = "single" | "double" | "short" | "full" \ No newline at end of file +export type monthType = "single" | "double" | "short" | "long"; +export type dateType = "single" | "double" | "short" | "long" | "dowsingle" | "dowdouble"; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index aab2b25..e73300f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ +import { dayDictionary } from "./Dictionaries/dateDictionary"; import { monthDictionary } from "./Dictionaries/monthDictionary"; -import { monthType } from "./Types/formatTypes"; +import { dateType, monthType } from "./Types/formatTypes"; @@ -30,7 +31,7 @@ export default class TymeJS { * Get the currently assigned date object * @returns The assigned Date object */ - public getDate(): Date { + public getDateObject(): Date { return this.ts; } @@ -53,7 +54,7 @@ export default class TymeJS { * Get the current month */ public getMonth(mType: monthType): string { - + // get the index of the current month let monthIndex: number = this.ts.getMonth(); if ( mType === "single" ) { @@ -68,6 +69,27 @@ export default class TymeJS { } + public getDate(dType: dateType): string { + + if ( dType == "single" ) { + // get the index of the current day + let currentDate: number = this.ts.getDate(); + return String(currentDate); + } else if ( dType == "double" ) { + // get the index of the current day + let currentDate: number = this.ts.getDate(); + return String(currentDate).padStart(2, "0"); + } else if ( dType == 'dowsingle' ) { + return String(this.ts.getDay()); + } else if ( dType == 'dowdouble' ) { + return String(this.ts.getDay()).padStart(2, "0"); + } else if ( dType == "short") { + return String(dayDictionary[this.ts.getDay() - 1]); + } else { + return String(dayDictionary[this.ts.getDay() - 1]).slice(0, 3); + } + } + } diff --git a/tests/dateTest.ts b/tests/dateTest.ts new file mode 100644 index 0000000..c5c352e --- /dev/null +++ b/tests/dateTest.ts @@ -0,0 +1,18 @@ +import TymeJS from "../src"; + +let startDate: Date = new Date(); + +for ( let i = 0; i < 7; i++ ) { + const a = new TymeJS(startDate); + console.log(startDate, { + single: a.getDate("single"), + double: a.getDate("double"), + dowsingle: a.getDate("dowsingle"), + dowdouble: a.getDate("dowdouble"), + full: a.getDate("long"), + short: a.getDate("short"), + }); + + startDate.setDate(startDate.getDate() + 1); +} + diff --git a/tests/monthTest.ts b/tests/monthTest.ts index 578fdb5..23c4ed8 100644 --- a/tests/monthTest.ts +++ b/tests/monthTest.ts @@ -10,7 +10,7 @@ for ( let i = 0; i < 12; i++ ) { console.log({ single: a.getMonth("single"), double: a.getMonth("double"), - full: a.getMonth("full"), + full: a.getMonth("long"), short: a.getMonth("short"), }); }