From eec5558d2114e8c0f73314d6d47debf4569b28a4 Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Sun, 1 Apr 2018 13:16:21 +0530 Subject: [PATCH] Add utils for time comparison, add css reset to index --- src/Utils/index.ts | 1 + src/Utils/utils.ts | 23 +++++++++++++++++++++++ src/index.css | 12 +++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/Utils/index.ts create mode 100644 src/Utils/utils.ts diff --git a/src/Utils/index.ts b/src/Utils/index.ts new file mode 100644 index 0000000..c3e1d0d --- /dev/null +++ b/src/Utils/index.ts @@ -0,0 +1 @@ +export { Utils, IndiaTZName } from './utils'; \ No newline at end of file diff --git a/src/Utils/utils.ts b/src/Utils/utils.ts new file mode 100644 index 0000000..18ece61 --- /dev/null +++ b/src/Utils/utils.ts @@ -0,0 +1,23 @@ +import * as moment from 'moment-timezone'; + +export const IndiaTZName = 'Asia/Kolkata'; + +export class Utils { + static createTodayDateInIndiaTZ(): moment.Moment { + return moment.tz(moment.tz.guess()).tz(IndiaTZName); + } + + static createDateFromEpochInIndiaTZ(dateEpoch: number): moment.Moment { + return moment.unix(dateEpoch).tz(IndiaTZName); + } + + static checkSameDayInSameTZ(moment1: moment.Moment, moment2: moment.Moment, raiseErrorTZMismatch: boolean = true) { + // tslint:disable-next-line:triple-equals + if (raiseErrorTZMismatch && (moment1.tz() != moment2.tz())) { + throw new Error('Timezones don\'t match'); + } + + // tslint:disable-next-line:triple-equals + return (moment1.clone().startOf('day').format() == moment2.clone().startOf('day').format()); + } +} \ No newline at end of file diff --git a/src/index.css b/src/index.css index b4cc725..4c1b2fc 100644 --- a/src/index.css +++ b/src/index.css @@ -1,5 +1,15 @@ -body { +*,*::before,*::after { + box-sizing: border-box; +} + +html, body { margin: 0; padding: 0; + + width: 100%; + height: 100%; +} + +body { font-family: sans-serif; }