mirror of
https://github.com/bendtherules/is-nifty-open.git
synced 2026-08-18 22:02:57 +00:00
Use moment-timezone + tz helpers + some OpenToday DOM changes
This commit is contained in:
+24
-20
@@ -1,8 +1,8 @@
|
||||
import * as Moment from 'moment';
|
||||
import * as moment from 'moment-timezone';
|
||||
|
||||
export interface Holiday {
|
||||
Description: string;
|
||||
Date: Moment.Moment;
|
||||
Date: moment.Moment;
|
||||
// Use it later, if needed
|
||||
Day: string;
|
||||
}
|
||||
@@ -11,24 +11,28 @@ export type HolidayList = Array<Holiday>;
|
||||
|
||||
export const allHolidays: HolidayList =
|
||||
[
|
||||
{ "Description": "Republic Day", "Date": Moment("2018-1-26"), "Day": "Friday" },
|
||||
{ "Description": "Mahashivratri", "Date": Moment("2018-2-13"), "Day": "Tuesday" },
|
||||
{ "Description": "Holi", "Date": Moment("2018-3-2"), "Day": "Friday" },
|
||||
{ "Description": "Mahavir Jayanti", "Date": Moment("2018-3-29"), "Day": "Thursday" },
|
||||
{ "Description": "Good Friday", "Date": Moment("2018-3-30"), "Day": "Friday" },
|
||||
{ "Description": "Maharashtra Day", "Date": Moment("2018-5-1"), "Day": "Tuesday" },
|
||||
{ "Description": "Independence Day", "Date": Moment("2018-8-15"), "Day": "Wednesday" },
|
||||
{ "Description": "Bakri ID", "Date": Moment("2018-8-22"), "Day": "Wednesday" },
|
||||
{ "Description": "Ganesh Chaturthi", "Date": Moment("2018-9-13"), "Day": "Thursday" },
|
||||
{ "Description": "Moharram", "Date": Moment("2018-9-20"), "Day": "Thursday" },
|
||||
{ "Description": "Mahatama Gandhi Jayanti", "Date": Moment("2018-10-2"), "Day": "Tuesday" },
|
||||
{ "Description": "Dasera", "Date": Moment("2018-10-18"), "Day": "Thursday" },
|
||||
{ "Description": "Diwali-Laxmi Pujan", "Date": Moment("2018-11-7"), "Day": "Wednesday" },
|
||||
{ "Description": "Diwali-Balipratipada", "Date": Moment("2018-11-8"), "Day": "Thursday" },
|
||||
{ "Description": "Gurunanak Jayanti", "Date": Moment("2018-11-23"), "Day": "Friday" },
|
||||
{ "Description": "Christmas", "Date": Moment("2018-12-25"), "Day": "Tuesday" },
|
||||
{ "Description": "Republic Day", "Date": parseDateInIndiaTZ("2018-1-26"), "Day": "Friday" },
|
||||
{ "Description": "Mahashivratri", "Date": parseDateInIndiaTZ("2018-2-13"), "Day": "Tuesday" },
|
||||
{ "Description": "Holi", "Date": parseDateInIndiaTZ("2018-3-2"), "Day": "Friday" },
|
||||
{ "Description": "Mahavir Jayanti", "Date": parseDateInIndiaTZ("2018-3-29"), "Day": "Thursday" },
|
||||
{ "Description": "Good Friday", "Date": parseDateInIndiaTZ("2018-3-30"), "Day": "Friday" },
|
||||
{ "Description": "Maharashtra Day", "Date": parseDateInIndiaTZ("2018-5-1"), "Day": "Tuesday" },
|
||||
{ "Description": "Independence Day", "Date": parseDateInIndiaTZ("2018-8-15"), "Day": "Wednesday" },
|
||||
{ "Description": "Bakri ID", "Date": parseDateInIndiaTZ("2018-8-22"), "Day": "Wednesday" },
|
||||
{ "Description": "Ganesh Chaturthi", "Date": parseDateInIndiaTZ("2018-9-13"), "Day": "Thursday" },
|
||||
{ "Description": "Moharram", "Date": parseDateInIndiaTZ("2018-9-20"), "Day": "Thursday" },
|
||||
{ "Description": "Mahatama Gandhi Jayanti", "Date": parseDateInIndiaTZ("2018-10-2"), "Day": "Tuesday" },
|
||||
{ "Description": "Dasera", "Date": parseDateInIndiaTZ("2018-10-18"), "Day": "Thursday" },
|
||||
{ "Description": "Diwali-Laxmi Pujan", "Date": parseDateInIndiaTZ("2018-11-7"), "Day": "Wednesday" },
|
||||
{ "Description": "Diwali-Balipratipada", "Date": parseDateInIndiaTZ("2018-11-8"), "Day": "Thursday" },
|
||||
{ "Description": "Gurunanak Jayanti", "Date": parseDateInIndiaTZ("2018-11-23"), "Day": "Friday" },
|
||||
{ "Description": "Christmas", "Date": parseDateInIndiaTZ("2018-12-25"), "Day": "Tuesday" },
|
||||
];
|
||||
|
||||
function parseDateInIndiaTZ(dateString: string): moment.Moment {
|
||||
return moment.tz(dateString, "YYYY-MM-DD", "Asia/Kolkata");
|
||||
}
|
||||
|
||||
export enum ISOWeekDay {
|
||||
Monday = 1,
|
||||
Tuesday = 2,
|
||||
@@ -39,7 +43,7 @@ export enum ISOWeekDay {
|
||||
Sunday = 7
|
||||
}
|
||||
|
||||
export function isWeekend(date: Moment.Moment): boolean {
|
||||
export function isWeekend(date: moment.Moment): boolean {
|
||||
const dateWeekDay = date.isoWeekday();
|
||||
if ((dateWeekDay === ISOWeekDay.Saturday) ||
|
||||
(dateWeekDay === ISOWeekDay.Sunday)) {
|
||||
@@ -49,7 +53,7 @@ export function isWeekend(date: Moment.Moment): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
export function getWeekendHoliday(date: Moment.Moment): Holiday | undefined {
|
||||
export function getWeekendHoliday(date: moment.Moment): Holiday | undefined {
|
||||
if (isWeekend(date)) {
|
||||
const dateWeekDay = date.isoWeekday();
|
||||
return { "Description": "Weekend", "Date": date, "Day": ISOWeekDay[dateWeekDay] };
|
||||
|
||||
Reference in New Issue
Block a user