feat: show am/pm on date

we are cheating by using Date.toLocaleString(), that is fixed to "en"
locale, for the time portion of the date
This commit is contained in:
Bobby 2022-05-06 20:45:40 +07:00
parent 395361d5fc
commit 4fa3a54729
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
2 changed files with 18 additions and 6 deletions

View File

@ -821,6 +821,15 @@ page.prepareUploadConfig = () => {
help: 'This will be used in our homepage, dashboard, and album public pages.',
valueHandler () {} // Do nothing
},
ampmTime: {
label: 'Show AM/PM on date',
select: [
{ value: 'default', text: 'No' },
{ value: '1', text: 'Yes' }
],
help: 'This will be used in our homepage and dashboard.',
valueHandler () {} // Do nothing
},
fileLength: {
display: fileIdentifierLength,
label: 'File identifier length',

View File

@ -2,6 +2,7 @@
// keys for localStorage
lsKeys.siBytes = 'siBytes'
lsKeys.ampmTime = 'ampmTime'
page.prepareShareX = () => {
const sharexElement = document.querySelector('#ShareX')
@ -46,17 +47,19 @@ page.prepareShareX = () => {
}
page.getPrettyDate = date => {
// Not using .toLocaleString() for date display to maintain a global standard,
// but its AM/PM logic is perfect for our use case as long as it's fixed to "en" locale.
return date.getFullYear() + '/' +
(date.getMonth() < 9 ? '0' : '') + // month's index starts from zero
(date.getMonth() + 1) + '/' +
(date.getDate() < 10 ? '0' : '') +
date.getDate() + ' ' +
(date.getHours() < 10 ? '0' : '') +
date.getHours() + ':' +
(date.getMinutes() < 10 ? '0' : '') +
date.getMinutes() + ':' +
(date.getSeconds() < 10 ? '0' : '') +
date.getSeconds()
date.toLocaleString('en', {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: localStorage[lsKeys.ampmTime] === '1'
})
}
page.getPrettyBytes = num => {