mirror of
https://github.com/bendtherules/is-nifty-open.git
synced 2026-08-19 00:32:31 +00:00
Refactor more util functions from app to utils file
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
export { Utils, HolidayAnswer, OpenOrClose } from "./utils";
|
||||
export { Utils, HolidayAnswer, OpenOrClose, OpenOrCloseOrClosed, DayNames } from "./utils";
|
||||
@@ -12,6 +12,18 @@ export enum OpenOrClose {
|
||||
Close = 'closed'
|
||||
}
|
||||
|
||||
export const enum OpenOrCloseOrClosed {
|
||||
Open = "open",
|
||||
Close = "close",
|
||||
Closed = "closed"
|
||||
}
|
||||
|
||||
export const enum DayNames {
|
||||
today = "today",
|
||||
tomorrow = "tomorrow",
|
||||
yesterday = "yesterday",
|
||||
}
|
||||
|
||||
export class Utils {
|
||||
static invertOpenOrClose(openOrClose: OpenOrClose) {
|
||||
return (openOrClose === OpenOrClose.Open) ? OpenOrClose.Close : OpenOrClose.Open;
|
||||
@@ -109,4 +121,29 @@ export class Utils {
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
static mapAbsoluteDateToRelativeDayName(xDay: moment.Moment): DayNames | undefined {
|
||||
// Redirect to relative if day is within +-1 day of today
|
||||
let tmpToday = Utils.createTodayDateInIndiaTZ();
|
||||
let tmpTomorrow = tmpToday.clone().add(1, "d");
|
||||
let tmpYesterday = tmpToday.clone().subtract(1, "d");
|
||||
|
||||
if (Utils.checkSameDayInSameTZ(xDay, tmpToday)) {
|
||||
|
||||
return DayNames.today;
|
||||
|
||||
} else if (Utils.checkSameDayInSameTZ(xDay, tmpTomorrow)) {
|
||||
|
||||
return DayNames.tomorrow;
|
||||
|
||||
} else if (Utils.checkSameDayInSameTZ(xDay, tmpYesterday)) {
|
||||
|
||||
return DayNames.yesterday;
|
||||
|
||||
} else {
|
||||
|
||||
return undefined;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user