diff --git a/src/Components/OpenToday/Component.tsx b/src/Components/OpenToday/Component.tsx new file mode 100644 index 0000000..cbed672 --- /dev/null +++ b/src/Components/OpenToday/Component.tsx @@ -0,0 +1,73 @@ +import * as React from 'react'; +import * as Moment from 'moment'; +import * as Linq from 'linq'; +import { Holiday, HolidayList, getWeekendHoliday } from '../../Data/index'; +import { ClosedReason } from '../ClosedReason'; + +export class OpenToday extends React.Component<{ + question: OpenToday.OpenOrClose, + allHolidays: HolidayList +}, {}> { + question: OpenToday.OpenOrClose; + allHolidays: HolidayList; + answer: { open: boolean, holiday: Holiday | undefined }; + + constructor(props: { question: OpenToday.OpenOrClose, allHolidays: HolidayList }) { + super(props); + this.question = props.question; + this.allHolidays = props.allHolidays; + + this.processAnswer(); + } + + processAnswer(): void { + var todayDateTime = Moment("2018-03-11"); + + { + const matchingHoliday = Linq + .from(this.allHolidays) + .firstOrDefault( + (eachHoliday, _tmp) => todayDateTime.isSame(eachHoliday.Date, 'day') + ); + + if (matchingHoliday === null) { + this.answer = { open: true, holiday: undefined }; + } else { + this.answer = { open: false, holiday: matchingHoliday }; + } + } + + { + const weekendHoliday = getWeekendHoliday(todayDateTime); + + if (typeof weekendHoliday !== "undefined") { + this.answer = { open: false, holiday: weekendHoliday }; + } + } + } + + render() { + const answerBoolean = (this.question === OpenToday.OpenOrClose.Open ? this.answer.open : !this.answer.open); + + return ( +
+
Is Nifty50 (NSE) {this.question} today?
+
+
+ {answerBoolean ? "Yes" : "No"} +
+ + {!this.answer.open ? : undefined} + +
+
+ ); + } +} + +export module OpenToday { + export enum OpenOrClose { + Open = 'open', + Close = 'closed' + } +} \ No newline at end of file diff --git a/src/Components/OpenToday/index.tsx b/src/Components/OpenToday/index.tsx new file mode 100644 index 0000000..769f881 --- /dev/null +++ b/src/Components/OpenToday/index.tsx @@ -0,0 +1 @@ +export { OpenToday } from './Component'; \ No newline at end of file