Days implementation
+ getDate + dayTypes
This commit is contained in:
17
src/Dictionaries/dateDictionary.ts
Normal file
17
src/Dictionaries/dateDictionary.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* A dictionary for all of the days of the week
|
||||
*/
|
||||
const dayDictionary: Array<string> = [
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
];
|
||||
|
||||
|
||||
export {
|
||||
dayDictionary
|
||||
};
|
||||
@@ -1 +1,2 @@
|
||||
export type monthType = "single" | "double" | "short" | "full"
|
||||
export type monthType = "single" | "double" | "short" | "long";
|
||||
export type dateType = "single" | "double" | "short" | "long" | "dowsingle" | "dowdouble";
|
||||
28
src/index.ts
28
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user