Compare commits
6 commits
e9aff483b1
...
af8ba14b83
Author | SHA1 | Date | |
---|---|---|---|
af8ba14b83 | |||
d9e7543238 | |||
b78ccb801f | |||
013dbf4974 | |||
7de418362e | |||
8f06e0221f |
7 changed files with 67 additions and 5 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -15,3 +15,6 @@ dist/
|
||||||
|
|
||||||
# Debug file
|
# Debug file
|
||||||
src/events/player/debug.ts
|
src/events/player/debug.ts
|
||||||
|
|
||||||
|
# Jest
|
||||||
|
coverage/
|
||||||
|
|
|
@ -291,8 +291,7 @@ Pour commencer, vous pouvez jeter un œil aux
|
||||||
Il est souhaité d'écrire des tests quand cela est possible.
|
Il est souhaité d'écrire des tests quand cela est possible.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
import { fnReturnsTrue } from "../src/utils/file";
|
||||||
const { fnReturnsTrue } = require("../src/utils/misc");
|
|
||||||
|
|
||||||
describe("test name", () => {
|
describe("test name", () => {
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,7 +45,7 @@ export type dbReminder = {
|
||||||
* @param time raw text from user
|
* @param time raw text from user
|
||||||
* @returns An object with the time and the option
|
* @returns An object with the time and the option
|
||||||
*/
|
*/
|
||||||
const splitTime = (time: string) => {
|
export const splitTime = (time: string) => {
|
||||||
if (time?.endsWith("@")) {
|
if (time?.endsWith("@")) {
|
||||||
return { time: time.slice(0, -1), option: OptionReminder.Mention };
|
return { time: time.slice(0, -1), option: OptionReminder.Mention };
|
||||||
} else if (time?.toLowerCase().endsWith("p")) {
|
} else if (time?.toLowerCase().endsWith("p")) {
|
||||||
|
|
|
@ -9,8 +9,9 @@ import moment from "moment-timezone";
|
||||||
*/
|
*/
|
||||||
export const showDate = (tz: string, locale: Map<string, unknown>, date: Date) => {
|
export const showDate = (tz: string, locale: Map<string, unknown>, date: Date) => {
|
||||||
const localeInfo = new Intl.Locale(tz);
|
const localeInfo = new Intl.Locale(tz);
|
||||||
|
const intlTimezone = moment.tz.zonesForCountry(localeInfo.region ?? localeInfo.baseName);
|
||||||
const formattedDate = new Intl.DateTimeFormat(tz, {
|
const formattedDate = new Intl.DateTimeFormat(tz, {
|
||||||
timeZone: moment.tz.zonesForCountry(localeInfo.region ?? localeInfo.baseName)[0],
|
timeZone: intlTimezone ? intlTimezone[0] : "Etc/GMT",
|
||||||
dateStyle: "short",
|
dateStyle: "short",
|
||||||
timeStyle: "medium",
|
timeStyle: "medium",
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {
|
||||||
isImage,
|
isImage,
|
||||||
removeExtension,
|
removeExtension,
|
||||||
splitFilenameExtensions,
|
splitFilenameExtensions,
|
||||||
} from "../src/utils/misc";
|
} from "../../src/utils/misc";
|
||||||
|
|
||||||
describe("Filename splitter", () => {
|
describe("Filename splitter", () => {
|
||||||
{
|
{
|
28
tests/utils/reminder.test.ts
Normal file
28
tests/utils/reminder.test.ts
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import { OptionReminder, splitTime } from "../../src/utils/reminder";
|
||||||
|
|
||||||
|
describe("Time splitter", () => {
|
||||||
|
{
|
||||||
|
const name = "";
|
||||||
|
test(name, () => {
|
||||||
|
expect(splitTime(name)).toStrictEqual({ option: OptionReminder.Nothing, time: "" });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const name = "2m@p";
|
||||||
|
test(name, () => {
|
||||||
|
expect(splitTime(name)).toStrictEqual({ option: OptionReminder.Mention, time: "2m" });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const name = "41@";
|
||||||
|
test(name, () => {
|
||||||
|
expect(splitTime(name)).toStrictEqual({ option: OptionReminder.Mention, time: "41" });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const name = "0P";
|
||||||
|
test(name, () => {
|
||||||
|
expect(splitTime(name)).toStrictEqual({ option: OptionReminder.DirectMessage, time: "0" });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
31
tests/utils/time.test.ts
Normal file
31
tests/utils/time.test.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import { showDate } from "../../src/utils/time";
|
||||||
|
|
||||||
|
describe("Date with correct timezone", () => {
|
||||||
|
const map: Map<string, unknown> = new Map([["u_time_at", "@"]]);
|
||||||
|
const date = new Date(1727434767686);
|
||||||
|
{
|
||||||
|
const name = "fr";
|
||||||
|
test(name, () => {
|
||||||
|
expect(showDate(name, map, date)).toBe("27/09/2024 @ 12:59:27");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const name = "en-US";
|
||||||
|
test(name, () => {
|
||||||
|
expect(showDate(name, map, date)).toBe("9/27/24, @ 1:59:27");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const name = "unknown";
|
||||||
|
test(name, () => {
|
||||||
|
expect(showDate(name, map, date)).toBe("27/09/2024 @ 10:59:27");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const name = "zh-CN";
|
||||||
|
test(name, () => {
|
||||||
|
expect(showDate(name, map, date)).toBe("2024/9/27 @ 18:59:27");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue