Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
日付の表現を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
takejohn committed Apr 27, 2024
1 parent 70ef413 commit 8172cad
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 5 deletions.
27 changes: 26 additions & 1 deletion language/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,32 @@
},
"defaultValues": {
"graphLabel": "value"
}
},
"dayNames": [
"日曜日",
"月曜日",
"火曜日",
"水曜日",
"木曜日",
"金曜日",
"土曜日"
],
"dayLabels": ["", "", "", "", "", "", ""],
"monthNames": [
"1月",
"2月",
"3月",
"4月",
"5月",
"6月",
"7月",
"8月",
"9月",
"10月",
"11月",
"12月"
],
"dateFormat": "${year}年${month}${date}日${day}"
},
"commands": {
"cal": {
Expand Down
27 changes: 26 additions & 1 deletion language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,32 @@
},
"defaultValues": {
"graphLabel": "value"
}
},
"dayNames": [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
],
"dayLabels": ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
"monthNames": [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
],
"dateFormat": "${day}, ${month} ${date}, ${year}"
},
"commands": {
"cal": {
Expand Down
27 changes: 26 additions & 1 deletion language/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,32 @@
},
"defaultValues": {
"graphLabel": "value"
}
},
"dayNames": [
"日曜日",
"月曜日",
"火曜日",
"水曜日",
"木曜日",
"金曜日",
"土曜日"
],
"dayLabels": ["", "", "", "", "", "", ""],
"monthNames": [
"1月",
"2月",
"3月",
"4月",
"5月",
"6月",
"7月",
"8月",
"9月",
"10月",
"11月",
"12月"
],
"dateFormat": "${year}年${month}${date}日${day}"
},
"commands": {
"cal": {
Expand Down
7 changes: 5 additions & 2 deletions packages/misc/commands/date.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { CompoundCommandBuilder } from '../../../common/CompoundCommand';
import { Day } from '../util/calendar';

const builder = new CompoundCommandBuilder('date', '時刻の計算と表示');

builder.subcommand('now', '現在時刻を表示').build(async (i) => {
await i.reply(new Date().toString());
builder.subcommand('now', '現在時刻を表示').build(async (interaction) => {
const date = new Date();
const day = new Day(date.getFullYear(), date.getMonth(), date.getDate());
await interaction.reply(day.toHumanReadable());
});

builder
Expand Down
14 changes: 14 additions & 0 deletions packages/misc/util/calendar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import { LANG, strFormat } from '../../../util/languages';

export const DayOfWeek = Object.freeze({
Sunday: 0,
Expand Down Expand Up @@ -64,9 +65,22 @@ export class Day {
return `${this.year}/${this.month + 1}/${this.date}`;
}

toHumanReadable() {
return strFormat(LANG.common.dateFormat, {
year: this.year,
month: LANG.common.monthNames[this.month],
date: this.date,
day: LANG.common.dayNames[this.day],
});
}

isHoliday() {
return holidays.has(this.toString());
}

holiday(): string | null {
return holidays.get(this.toString()) ?? null;
}
}

export type Week = { [K in DayOfWeek]: Day } & Array<Day>;
Expand Down

0 comments on commit 8172cad

Please sign in to comment.