mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-15 06:05:03 +00:00
Add support for server-specific timezone and date format settings
This commit is contained in:
parent
ddbbc543c2
commit
c67a1df11d
51 changed files with 326 additions and 168 deletions
21
backend/src/utils/timezones.ts
Normal file
21
backend/src/utils/timezones.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import moment from "moment-timezone";
|
||||
import { PluginData } from "knub";
|
||||
import { ZeppelinGuildConfig } from "../types";
|
||||
|
||||
export function getGuildTz(pluginData: PluginData<any>) {
|
||||
const guildConfig = pluginData.guildConfig as ZeppelinGuildConfig;
|
||||
return guildConfig.timezone || "Etc/UTC";
|
||||
}
|
||||
|
||||
export function inGuildTz(pluginData: PluginData<any>, input?: moment.Moment | number) {
|
||||
let momentObj: moment.Moment;
|
||||
if (typeof input === "number") {
|
||||
momentObj = moment.utc(input, "x");
|
||||
} else if (moment.isMoment(input)) {
|
||||
momentObj = input.clone();
|
||||
} else {
|
||||
momentObj = moment.utc();
|
||||
}
|
||||
|
||||
return momentObj.tz(getGuildTz(pluginData));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue