Skip to content

Commit a509657

Browse files
committed
Add days in default time format (sheepzh#411)
1 parent 28c7121 commit a509657

File tree

8 files changed

+41
-60
lines changed

8 files changed

+41
-60
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"Auths",
1717
"Cascader",
1818
"clbbddpinhgdejpoepalbfnkogbobfdb",
19+
"COPYFILE",
1920
"countup",
2021
"daterange",
2122
"domcontentloaded",
@@ -44,6 +45,7 @@
4445
"webstore",
4546
"webtime",
4647
"wfhg",
48+
"zcvf",
4749
"zrender"
4850
],
4951
"cSpell.ignorePaths": [

script/zip.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ FOLDER=$(
66
)
77
TARGET_PATH="${FOLDER}/aaa"
88

9-
tar -zcvf ${TARGET_PATH} \
9+
COPYFILE_DISABLE=1 tar -zcvf ${TARGET_PATH} \
1010
--exclude=dist*/ \
1111
--exclude=.git/ \
1212
--exclude=package-lock.json \

src/content-script/printer.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,18 @@
66
*/
77

88
import { sendMsg2Runtime } from "@api/chrome/runtime"
9-
import { formatPeriod } from "@util/time"
9+
import { formatPeriodCommon } from "@util/time"
1010
import { t } from "./locale"
1111

1212
/**
1313
* Print info of today
1414
*/
1515
export default async function printInfo(host: string) {
1616
const waste: timer.core.Result = await sendMsg2Runtime('cs.getTodayInfo', host)
17-
const hourMsg = t(msg => msg.console.timeWithHour)
18-
const minuteMsg = t(msg => msg.console.timeWithMinute)
19-
const secondMsg = t(msg => msg.console.timeWithSecond)
20-
21-
const msg = { hourMsg, minuteMsg, secondMsg }
2217

2318
const param = {
2419
time: waste.time ? '' + waste.time : '-',
25-
focus: formatPeriod(waste.focus, msg),
20+
focus: formatPeriodCommon(waste.focus),
2621
host,
2722
}
2823
const info0 = t(msg => msg.console.consoleLog, param)
Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,42 @@
11
{
22
"zh_CN": {
33
"consoleLog": "今天您打开了 {time} 次 {host},花费了 {focus} 来浏览它。",
4-
"closeAlert": "你可以在【网费很贵】的选项中关闭以上提示!",
5-
"timeWithHour": "{hour} 小时 {minute} 分 {second} 秒",
6-
"timeWithMinute": "{minute} 分 {second} 秒",
7-
"timeWithSecond": "{second} 秒"
4+
"closeAlert": "你可以在【网费很贵】的选项中关闭以上提示!"
85
},
96
"zh_TW": {
107
"consoleLog": "今天您打開了 {time} 次 {host},花費了 {focus} 來瀏覽它。",
11-
"closeAlert": "你可以在【{appName}】的選項中關閉以上提示!",
12-
"timeWithHour": "{hour} 小時 {minute} 分 {second} 秒",
13-
"timeWithMinute": "{minute} 分 {second} 秒",
14-
"timeWithSecond": "{second} 秒"
8+
"closeAlert": "你可以在【{appName}】的選項中關閉以上提示!"
159
},
1610
"en": {
1711
"consoleLog": "You have open {host} for {time} time(s) and browsed it for {focus} today.",
18-
"closeAlert": "You can turn off the above tips in the option of [{appName}]!",
19-
"timeWithHour": "{hour} hour(s) {minute} minute(s) {second} second(s)",
20-
"timeWithMinute": "{minute} minute(s) {second} second(s)",
21-
"timeWithSecond": "{second} second(s)"
12+
"closeAlert": "You can turn off the above tips in the option of [{appName}]!"
2213
},
2314
"ja": {
2415
"consoleLog": "{host} を {time} 回開いて、今日 {focus} をブラウズしました。",
25-
"closeAlert": "{appName} のオプションで上記のヒントをオフにすることができます!",
26-
"timeWithHour": "{hour} 時間 {minute} 分 {second} 秒",
27-
"timeWithMinute": "{minute} 分 {second} 秒",
28-
"timeWithSecond": "{second} 秒"
16+
"closeAlert": "{appName} のオプションで上記のヒントをオフにすることができます!"
2917
},
3018
"pt_PT": {
3119
"consoleLog": "Abriu {host} por {time} vez(es) e navegou por {focus} hoje.",
32-
"closeAlert": "Você pode desligar as dicas acima na opção do {appName}!",
33-
"timeWithHour": "{hour} horas {minute} minutos {second} segundos",
34-
"timeWithMinute": "{minute} minuto(s) {second} segundo(s)",
35-
"timeWithSecond": "{second} segundo(s)"
20+
"closeAlert": "Você pode desligar as dicas acima na opção do {appName}!"
3621
},
3722
"uk": {
3823
"consoleLog": "Сьогодні ви відкривали {host} {time} разів і перебували там {focus}.",
39-
"closeAlert": "Ви можете вимкнути поради в налаштуваннях [{appName}]!",
40-
"timeWithHour": "{hour} год {minute} хв {second} с",
41-
"timeWithMinute": "{minute} хв {second} с",
42-
"timeWithSecond": "{second} с"
24+
"closeAlert": "Ви можете вимкнути поради в налаштуваннях [{appName}]!"
4325
},
4426
"es": {
4527
"consoleLog": "Has abierto {host} por {time} vez(veces) y navegado por {focus} hoy.",
46-
"closeAlert": "¡Puedes desactivar los consejos de arriba en la opción de [{appName}]!",
47-
"timeWithHour": "{hour} hora(s) {minute} minuto(s) {second} segundo(s)",
48-
"timeWithMinute": "{minute} minuto(s) {second} segundo(s)",
49-
"timeWithSecond": "{second} segundo(s)"
28+
"closeAlert": "¡Puedes desactivar los consejos de arriba en la opción de [{appName}]!"
5029
},
5130
"de": {
5231
"consoleLog": "Sie haben {host} für {time} Mal(e) geöffnet und heute {focus} durchsucht.",
53-
"closeAlert": "Sie können die oben genannten Tipps in der Option [{appName}] deaktivieren!",
54-
"timeWithHour": "{hour} Stunden {minute} Minuten {second} Sekunden",
55-
"timeWithMinute": "{minute} Minuten {second} Sekunden",
56-
"timeWithSecond": "{seconds} Sekunde(n)"
32+
"closeAlert": "Sie können die oben genannten Tipps in der Option [{appName}] deaktivieren!"
5733
},
5834
"fr": {
5935
"consoleLog": "Vous avez ouvert {host} pendant {time} fois et vous l'avez parcouru pendant {focus} aujourd'hui.",
60-
"closeAlert": "Vous pouvez désactiver les conseils ci-dessus dans l'option [{appName}] !",
61-
"timeWithHour": "{heure} heures {minute} minutes {seconde} secondes",
62-
"timeWithMinute": "{minute} minutes {seconde} secondes",
63-
"timeWithSecond": "{second} seconds"
36+
"closeAlert": "Vous pouvez désactiver les conseils ci-dessus dans l'option [{appName}] !"
6437
},
6538
"ru": {
6639
"consoleLog": "Вы открыли {host} для {time} раз(а) и просматривали его сегодня для {focus}.",
67-
"closeAlert": "Вы можете выключить вышеперечисленные советы по адресу [{appName}]!",
68-
"timeWithHour": "{hour} часов {minute} минут {second} секунд",
69-
"timeWithMinute": "{minute} минут {second} секунд",
70-
"timeWithSecond": "{second} секунд"
40+
"closeAlert": "Вы можете выключить вышеперечисленные советы по адресу [{appName}]!"
7141
}
7242
}

src/i18n/message/cs/console.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import resource from './console-resource.json'
33
export type ConsoleMessage = {
44
consoleLog: string
55
closeAlert: string
6-
timeWithHour: string
7-
timeWithMinute: string
8-
timeWithSecond: string
96
}
107

118
const _default: Messages<ConsoleMessage> = resource

src/pages/app/components/Limit/LimitTable/RuleContent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ElTag } from "element-plus"
66
import { computed, defineComponent, toRef, type PropType } from "vue"
77

88
const TIME_FORMAT = {
9+
dayMsg: '{day}d{hour}h{minute}m{second}s',
910
hourMsg: '{hour}h{minute}m{second}s',
1011
minuteMsg: '{minute}m{second}s',
1112
secondMsg: '{second}s',

src/util/time.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,29 @@ export function formatTimeYMD(time: Date | string | number) {
6464
/**
6565
* Format milliseconds for display
6666
*/
67-
export function formatPeriod(milliseconds: number, message: { hourMsg: string, minuteMsg: string, secondMsg: string }): string {
67+
export function formatPeriod(milliseconds: number, message: Record<'dayMsg' | 'hourMsg' | 'minuteMsg' | 'secondMsg', string>): string {
6868
const prefix = milliseconds < 0 ? '-' : ''
6969
milliseconds = Math.abs(milliseconds)
70-
const { hourMsg, minuteMsg, secondMsg } = message
70+
const { dayMsg, hourMsg, minuteMsg, secondMsg } = message
7171
const seconds = Math.floor(milliseconds / 1000)
72-
const hour = Math.floor(seconds / 3600)
73-
const minute = Math.floor(seconds / 60 - hour * 60)
74-
const second = seconds - hour * 3600 - minute * 60
75-
76-
let msg = hourMsg
77-
hour === 0 && (msg = minuteMsg) && minute === 0 && (msg = secondMsg)
78-
const result = msg.replace('{hour}', hour.toString())
72+
const day = Math.floor(seconds / 86400)
73+
const hour = Math.floor(seconds / 3600 - day * 24)
74+
const minute = Math.floor(seconds / 60 - (day * 24 + hour) * 60)
75+
const second = seconds - day * 86400 - hour * 3600 - minute * 60
76+
77+
let msg = dayMsg
78+
if (!day) {
79+
msg = hourMsg
80+
if (!hour) {
81+
msg = minuteMsg
82+
if (!minute) {
83+
msg = secondMsg
84+
}
85+
}
86+
}
87+
const result = msg
88+
.replace('{day}', day.toString())
89+
.replace('{hour}', hour.toString())
7990
.replace('{minute}', minute.toString())
8091
.replace('{second}', second.toString())
8192
return prefix + result
@@ -94,10 +105,12 @@ export function formatPeriod(milliseconds: number, message: { hourMsg: string, m
94105
*/
95106
export function formatPeriodCommon(milliseconds: number): string {
96107
const defaultMessage = isRtl() ? {
108+
dayMsg: 's {second} m {minute} h {hour} d',
97109
hourMsg: 's {second} m {minute} h {hour}',
98110
minuteMsg: 's {second} m {minute}',
99111
secondMsg: 's {second}',
100112
} : {
113+
dayMsg: '{day} d {hour} h {minute} m {second} s',
101114
hourMsg: '{hour} h {minute} m {second} s',
102115
minuteMsg: '{minute} m {second} s',
103116
secondMsg: '{second} s',

test/util/time.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ test('time', () => {
3131

3232
test('format', () => {
3333
const msg = {
34+
dayMsg: '{day}天{hour}时{minute}分{second}秒',
3435
hourMsg: '{hour}时{minute}分{second}秒',
3536
minuteMsg: '{minute}分{second}秒',
3637
secondMsg: '{second}秒'
3738
}
39+
expect(formatPeriod(86400 * 1000, msg)).toEqual('1天0时0分0秒')
3840
expect(formatPeriod(3666 * 1000, msg)).toEqual('1时1分6秒')
41+
expect(formatPeriodCommon(86400 * 1000)).toEqual('1 d 0 h 0 m 0 s')
3942
expect(formatPeriodCommon(3666 * 1000)).toEqual('1 h 1 m 6 s')
4043
expect(formatPeriodCommon(1)).toEqual('0 s')
4144
})

0 commit comments

Comments
 (0)