mirror of
https://github.com/lukevella/rallly.git
synced 2025-05-28 08:16:22 +02:00
⬆️ v3.0.0 (#704)
This commit is contained in:
parent
735056f25f
commit
c22b3abc4d
385 changed files with 19912 additions and 5250 deletions
33
packages/backend/utils/date.ts
Normal file
33
packages/backend/utils/date.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import dayjs from "dayjs";
|
||||
import localizedFormat from "dayjs/plugin/localizedFormat";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import spacetime from "spacetime";
|
||||
import soft from "timezone-soft";
|
||||
|
||||
dayjs.extend(localizedFormat);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export const getTimeZoneAbbreviation = (date: Date, timeZone: string) => {
|
||||
const timeZoneDisplayFormat = soft(timeZone)[0];
|
||||
const spaceTimeDate = spacetime(date, timeZone);
|
||||
const standardAbbrev = timeZoneDisplayFormat.standard.abbr;
|
||||
const dstAbbrev = timeZoneDisplayFormat.daylight?.abbr;
|
||||
const abbrev = spaceTimeDate.isDST() ? dstAbbrev : standardAbbrev;
|
||||
return abbrev;
|
||||
};
|
||||
|
||||
export const printDate = (date: Date, duration: number, timeZone?: string) => {
|
||||
if (duration === 0) {
|
||||
return dayjs(date).format("LL");
|
||||
} else if (timeZone) {
|
||||
return `${dayjs(date).tz(timeZone).format("LLL")} - ${dayjs(date)
|
||||
.add(duration, "minutes")
|
||||
.tz(timeZone)
|
||||
.format("LT")} ${getTimeZoneAbbreviation(date, timeZone)}`;
|
||||
} else {
|
||||
return `${dayjs(date).utc().format("LLL")} - ${dayjs(date)
|
||||
.utc()
|
||||
.add(duration, "minutes")
|
||||
.format("LT")}`;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue