mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-09-16 18:06:55 +00:00
Implement timestamp formatting for chat lines (#526)
This commit is contained in:
parent
5b424fd363
commit
3eb947697c
3 changed files with 30 additions and 12 deletions
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -2449,6 +2449,11 @@
|
|||
"integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=",
|
||||
"dev": true
|
||||
},
|
||||
"dayjs": {
|
||||
"version": "1.7.7",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.7.7.tgz",
|
||||
"integrity": "sha512-Qlkiu0NNDpYwhk0syK4ImvAl/5YnsEMkvC2O123INviGeOA3Q8s5VyVkZzmN5SC7Wv9bb1+rfwO+uSqtHB4UWw=="
|
||||
},
|
||||
"de-indent": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz",
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"crypto-js": "^3.1.9-1",
|
||||
"dayjs": "^1.7.7",
|
||||
"displacejs": "^1.2.4",
|
||||
"emoji-regex": "^6.5.1",
|
||||
"graphql": "^0.13.2",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
// ============================================================================
|
||||
// Chat
|
||||
// ============================================================================
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import Module from 'utilities/module';
|
||||
import {createElement, ManagedStyle} from 'utilities/dom';
|
||||
|
@ -521,6 +522,26 @@ export default class Chat extends Module {
|
|||
}
|
||||
});
|
||||
|
||||
this.settings.add('chat.timestamp-format', {
|
||||
default: 'H:mm',
|
||||
ui: {
|
||||
path: 'Chat > Appearance >> Chat Lines',
|
||||
title: 'Timestamp Format',
|
||||
component: 'setting-select-box',
|
||||
|
||||
data: [
|
||||
{value: 'h:mm', title: 'Default (h:mm)'},
|
||||
{value: 'h:mm:ss', title: 'Default with Seconds (h:mm:ss)'},
|
||||
{value: 'H:mm', title: '24 Hour (H:mm)'},
|
||||
{value: 'H:mm:ss', title: '24 Hour with Seconds (H:mm:ss)'},
|
||||
{value: 'hh:mm', title: 'Padded (hh:mm)'},
|
||||
{value: 'hh:mm:ss', title: 'Padded with Seconds (hh:mm:ss)'},
|
||||
{value: 'HH:mm', title: 'Padded 24 Hour (HH:mm)'},
|
||||
{value: 'HH:mm:ss', title: 'Padded 24 Hour with Seconds (HH:mm:ss)'},
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
this.context.on('changed:theme.is-dark', () => {
|
||||
for(const room of this.iterateRooms())
|
||||
room.buildBitsCSS();
|
||||
|
@ -914,22 +935,13 @@ export default class Chat extends Module {
|
|||
}
|
||||
|
||||
|
||||
formatTime(time) { // eslint-disable-line class-methods-use-this
|
||||
formatTime(time) {
|
||||
if (!( time instanceof Date ))
|
||||
time = new Date(time);
|
||||
|
||||
let hours = time.getHours();
|
||||
const fmt = this.settings.get('chat.timestamp-format');
|
||||
|
||||
const minutes = time.getMinutes(); //,
|
||||
// seconds = time.getSeconds(),
|
||||
// fmt = this.settings.get('chat.timestamp-format');
|
||||
|
||||
if ( hours > 12 )
|
||||
hours -= 12;
|
||||
else if ( hours === 0 )
|
||||
hours = 12;
|
||||
|
||||
return `${hours}:${minutes < 10 ? '0' : ''}${minutes}`; //:${seconds < 10 ? '0' : ''}${seconds}`;
|
||||
return dayjs(time).format(fmt);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue