aboutsummaryrefslogtreecommitdiff
path: root/src/models/EventInfo.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/models/EventInfo.ts')
-rw-r--r--src/models/EventInfo.ts88
1 files changed, 51 insertions, 37 deletions
diff --git a/src/models/EventInfo.ts b/src/models/EventInfo.ts
index 962ec70..b0ac25b 100644
--- a/src/models/EventInfo.ts
+++ b/src/models/EventInfo.ts
@@ -1,46 +1,60 @@
-export default class EventInfo {
- days: string;
-
- start: number;
-
- end: number;
-
- constructor(days: string = '', start = 0, end = 0) {
- this.days = days;
- this.start = start;
- this.end = end;
- }
-
- static timeToStr(time: number) {
- let hour = Math.floor(time / 100);
- const minute = time % 100;
- const meridiem = (hour < 12) ? 'AM' : 'PM';
+interface EventInfoSerializeInfo {
+ days: string,
+ start: number,
+ end: number
+}
- if (hour === 0) {
- hour = 12;
- } else if (hour > 12) {
- hour -= 12;
+export default class EventInfo {
+ days: string;
+ start: number;
+ end: number;
+
+ constructor(days: string, start: number | string, end: number | string) {
+ if (typeof start === "string") {
+ start = parseInt(start, 10);
+ }
+ if (typeof end === "string") {
+ end = parseInt(end, 10);
+ }
+
+ this.days = days;
+ this.start = start;
+ this.end = end;
}
- if (minute < 10) {
- return `${hour}:0${minute} ${meridiem}`;
+ static fromJSON({days, start, end}: EventInfoSerializeInfo) {
+ return new EventInfo(days, start, end);
}
- return `${hour}:${minute} ${meridiem}`;
- }
- conflictsWith(event: EventInfo) {
- const daysConflict = event.days.match(new RegExp(`[${this.days}]`));
+ static timeToStr(time: number) {
+ let hour = Math.floor(time / 100);
+ const minute = time % 100;
+ const meridiem = (hour < 12) ? 'AM' : 'PM';
+
+ if (hour === 0) {
+ hour = 12;
+ } else if (hour > 12) {
+ hour -= 12;
+ }
+
+ if (minute < 10) {
+ return `${hour}:0${minute} ${meridiem}`;
+ }
+ return `${hour}:${minute} ${meridiem}`;
+ }
- if (daysConflict) {
- return (this.start <= event.end) && (event.start <= this.end);
+ conflictsWith(event: EventInfo) {
+ const daysConflict = event.days.match(new RegExp(`[${this.days}]`));
+ return daysConflict && this.start <= event.end && event.start <= this.end;
}
- return false;
- }
- get info() {
- if (this.days === '') {
- return 'WEB';
+ get info() {
+ if(this.days === "") {
+ return `WEB`;
+ }else if(this.start === -1 || this.end === -1) {
+ return `${this.days}`;
+ } else {
+ return `${this.days} ${EventInfo.timeToStr(this.start)}-${EventInfo.timeToStr(this.end)}`;
+ }
}
- return `${this.days} ${EventInfo.timeToStr(this.start)}-${EventInfo.timeToStr(this.end)}`;
- }
-}
+} \ No newline at end of file