mirror of
https://github.com/bendtherules/is-nifty-open.git
synced 2026-08-18 13:52:20 +00:00
Refactor more util functions from app to utils file
This commit is contained in:
@@ -6,46 +6,9 @@ import { OpenXDay } from '../OpenXDay';
|
||||
import { OpenXDayMini } from '../OpenXDayMini';
|
||||
import { NextOpenCloseMini } from '../NextOpenCloseMini';
|
||||
import { allHolidays } from '../../Data';
|
||||
import { Utils, OpenOrClose } from "../../Utils";
|
||||
|
||||
const enum OpenOrCloseOrClosed {
|
||||
Open = "open",
|
||||
Close = "close",
|
||||
Closed = "closed"
|
||||
}
|
||||
|
||||
const enum DayNames {
|
||||
today = "today",
|
||||
tomorrow = "tomorrow",
|
||||
yesterday = "yesterday",
|
||||
}
|
||||
import { Utils, OpenOrClose, OpenOrCloseOrClosed, DayNames } from "../../Utils";
|
||||
|
||||
class IsNiftyOpenApp extends React.Component {
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
calcOpenOrCloseForOpenCloseMini(xDay: moment.Moment) {
|
||||
var isTodayEventHoliday = Utils.getEventHolidayOnDate(xDay, allHolidays) !== undefined;
|
||||
|
||||
@@ -53,7 +16,7 @@ class IsNiftyOpenApp extends React.Component {
|
||||
}
|
||||
|
||||
returnRedirectToDayNamePathIfPossible(openOrClose: OpenOrClose, xDay: moment.Moment): JSX.Element | undefined {
|
||||
var relativeDayName = IsNiftyOpenApp.mapAbsoluteDateToRelativeDayName(xDay);
|
||||
var relativeDayName = Utils.mapAbsoluteDateToRelativeDayName(xDay);
|
||||
if (relativeDayName !== undefined) {
|
||||
return this.redirectToOpenRelativeDay(openOrClose, relativeDayName);
|
||||
} else {
|
||||
|
||||
+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