Skip to content

Commit

Permalink
Merge pull request #984 from OneUptime/master
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
simlarsen authored Nov 30, 2023
2 parents 10f6285 + 24b71c4 commit 2fece45
Show file tree
Hide file tree
Showing 68 changed files with 4,608 additions and 2,162 deletions.
604 changes: 320 additions & 284 deletions AdminDashboard/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions AdminDashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "0.1.0",
"private": false,
"dependencies": {
"@headlessui/react": "^1.7.7",
"@headlessui/react": "^1.7.17",
"@heroicons/react": "^2.0.13",
"@stripe/react-stripe-js": "^1.15.0",
"@stripe/stripe-js": "^1.44.1",
"@stripe/stripe-js": "^1.54.2",
"Common": "file:../Common",
"CommonServer": "file:../CommonServer",
"CommonUI": "file:../CommonUI",
Expand All @@ -15,10 +15,10 @@
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
"react-dom": "^18.1.0",
"react-icons": "^4.4.0",
"react-icons": "^4.11.0",
"react-router": "^6.19.0",
"react-router-dom": "^6.18.0",
"reactflow": "^11.5.3",
"reactflow": "^11.9.4",
"stripe": "^11.0.0",

"use-async-effect": "^2.2.6"
Expand Down
48 changes: 24 additions & 24 deletions ApiReference/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ApiReference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"dep-check": "depcheck ./ --skip-missing=true --ignores='ejs,puppeteer'"
},
"dependencies": {
"@types/body-parser": "^1.19.2",
"@types/cli-table": "^0.3.0",
"@types/body-parser": "^1.19.4",
"@types/cli-table": "^0.3.3",
"@types/compression": "^1.7.2",
"@types/ejs": "^3.1.4",
"@types/minify": "^8.0.0",
Expand Down
12 changes: 12 additions & 0 deletions Common/Types/Calendar/CalendarEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { JSONObject } from '../JSON';

export default interface CalendarEvent extends JSONObject {
id: number;
title: string;
start: Date;
end: Date;
allDay?: boolean | undefined;
desc?: string | undefined;
color?: string | undefined;
textColor?: string | undefined;
}
122 changes: 122 additions & 0 deletions Common/Types/Date.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import InBetween from './Database/InBetween';
import DayOfWeek from './Day/DayOfWeek';
import BadDataException from './Exception/BadDataException';
import { JSONObject, ObjectType } from './JSON';
import PositiveNumber from './PositiveNumber';
import moment from 'moment-timezone';

export const Moment: typeof moment = moment;

export default class OneUptimeDate {
public static getCurrentDate(): Date {
return moment().toDate();
Expand All @@ -21,6 +24,19 @@ export default class OneUptimeDate {
return moment();
}

public static keepTimeButMoveDay(keepTimeFor: Date, moveDayTo: Date): Date {
keepTimeFor = this.fromString(keepTimeFor);
moveDayTo = this.fromString(moveDayTo);
return moment(moveDayTo)
.set({
hour: keepTimeFor.getHours(),
minute: keepTimeFor.getMinutes(),
second: keepTimeFor.getSeconds(),
millisecond: keepTimeFor.getMilliseconds(),
})
.toDate();
}

public static getOneMinAgo(): Date {
return this.getSomeMinutesAgo(new PositiveNumber(1));
}
Expand Down Expand Up @@ -85,11 +101,78 @@ export default class OneUptimeDate {
};
}

public static areOnTheSameDay(date1: Date, date2: Date): boolean {
date1 = this.fromString(date1);
date2 = this.fromString(date2);
return moment(date1).isSame(date2, 'day');
}

public static areOnTheSameMonth(date1: Date, date2: Date): boolean {
date1 = this.fromString(date1);
date2 = this.fromString(date2);
return moment(date1).isSame(date2, 'month');
}

public static areOnTheSameYear(date1: Date, date2: Date): boolean {
date1 = this.fromString(date1);
date2 = this.fromString(date2);
return moment(date1).isSame(date2, 'year');
}

public static areOnTheSameHour(date1: Date, date2: Date): boolean {
date1 = this.fromString(date1);
date2 = this.fromString(date2);
return moment(date1).isSame(date2, 'hour');
}

public static areOnTheSameMinute(date1: Date, date2: Date): boolean {
date1 = this.fromString(date1);
date2 = this.fromString(date2);
return moment(date1).isSame(date2, 'minute');
}

public static areOnTheSameSecond(date1: Date, date2: Date): boolean {
date1 = this.fromString(date1);
date2 = this.fromString(date2);
return moment(date1).isSame(date2, 'second');
}

public static areOnTheSameWeek(date1: Date, date2: Date): boolean {
date1 = this.fromString(date1);
date2 = this.fromString(date2);
return moment(date1).isSame(date2, 'week');
}

public static addRemoveMinutes(date: Date, minutes: number): Date {
date = this.fromString(date);
return moment(date).add(minutes, 'minutes').toDate();
}

public static addRemoveDays(date: Date, days: number): Date {
date = this.fromString(date);
return moment(date).add(days, 'days').toDate();
}

public static addRemoveHours(date: Date, hours: number): Date {
date = this.fromString(date);
return moment(date).add(hours, 'hours').toDate();
}

public static addRemoveYears(date: Date, years: number): Date {
date = this.fromString(date);
return moment(date).add(years, 'years').toDate();
}

public static addRemoveMonths(date: Date, months: number): Date {
date = this.fromString(date);
return moment(date).add(months, 'months').toDate();
}

public static addRemoveWeeks(date: Date, weeks: number): Date {
date = this.fromString(date);
return moment(date).add(weeks, 'weeks').toDate();
}

public static addRemoveSeconds(date: Date, seconds: number): Date {
date = this.fromString(date);
return moment(date).add(seconds, 'seconds').toDate();
Expand Down Expand Up @@ -359,6 +442,45 @@ export default class OneUptimeDate {
return moment(date).isAfter(startDate);
}

public static isOnOrAfter(date: Date, startDate: Date): boolean {
date = this.fromString(date);
startDate = this.fromString(startDate);
return moment(date).isSameOrAfter(startDate);
}

public static getDayOfWeek(date: Date): DayOfWeek {
const dayOfWeek: number = this.geyDayOfWeekAsNumber(date);

if (dayOfWeek === 1) {
return DayOfWeek.Monday;
} else if (dayOfWeek === 2) {
return DayOfWeek.Tuesday;
} else if (dayOfWeek === 3) {
return DayOfWeek.Wednesday;
} else if (dayOfWeek === 4) {
return DayOfWeek.Thursday;
} else if (dayOfWeek === 5) {
return DayOfWeek.Friday;
} else if (dayOfWeek === 6) {
return DayOfWeek.Saturday;
} else if (dayOfWeek === 7) {
return DayOfWeek.Sunday;
}

throw new BadDataException('Invalid day of week');
}

public static geyDayOfWeekAsNumber(date: Date): number {
date = this.fromString(date);
return moment(date).isoWeekday();
}

public static isOnOrBefore(date: Date, endDate: Date): boolean {
date = this.fromString(date);
endDate = this.fromString(endDate);
return moment(date).isSameOrBefore(endDate);
}

public static isEqualBySeconds(date: Date, startDate: Date): boolean {
date = this.fromString(date);
startDate = this.fromString(startDate);
Expand Down
1 change: 1 addition & 0 deletions Common/Types/Events/EventInterval.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
enum EventInterval {
Hour = 'Hour',
Day = 'Day',
Week = 'Week',
Month = 'Month',
Expand Down
Loading

0 comments on commit 2fece45

Please sign in to comment.