Days implementation

+ getDate
+ dayTypes
This commit is contained in:
2022-05-06 01:07:13 +03:00
parent 1112a92023
commit c596812d30
6 changed files with 67 additions and 6 deletions

View 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
};

View File

@@ -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";

View File

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