This commit is contained in:
the-djmaze 2022-12-12 13:03:41 +01:00
parent c27e231f53
commit d0db7f5ce3
47 changed files with 95 additions and 18 deletions

View file

@ -4,6 +4,7 @@ import { langLink } from 'Common/Links';
import { doc, createElement } from 'Common/Globals';
import { getKeyByValue, forEachObjectEntry } from 'Common/Utils';
import { pInt } from 'Common/Utils';
import { LanguageStore } from 'Stores/Language';
let I18N_DATA = {};
@ -87,17 +88,17 @@ export const
const mt = m.getTime(), date = new Date,
dt = date.setHours(0,0,0,0);
if (mt > dt)
return i18n('MESSAGE_LIST/TODAY_AT', {TIME: m.format('LT')});
return i18n('MESSAGE_LIST/TODAY_AT', {TIME: m.format('LT',0,LanguageStore.hourCycle())});
if (mt > dt - 86400000)
return i18n('MESSAGE_LIST/YESTERDAY_AT', {TIME: m.format('LT')});
return i18n('MESSAGE_LIST/YESTERDAY_AT', {TIME: m.format('LT',0,LanguageStore.hourCycle())});
if (date.getFullYear() === m.getFullYear())
return m.format('d M');
return m.format('LL');
return m.format('LL',0,LanguageStore.hourCycle());
}
case 'FULL':
return m.format('LLL');
return m.format('LLL',0,LanguageStore.hourCycle());
default:
return m.format(formatStr);
return m.format(formatStr,0,LanguageStore.hourCycle());
}
}

View file

@ -19,6 +19,8 @@ import { AbstractModel } from 'Knoin/AbstractModel';
import PreviewHTML from 'Html/PreviewMessage.html';
import { LanguageStore } from 'Stores/Language';
//import { MessageFlagsCache } from 'Common/Cache';
import Remote from 'Remote/User/Fetch';
@ -456,7 +458,7 @@ export class MessageModel extends AbstractModel {
sdoc.write(PreviewHTML
.replace('<title>', '<title>'+subject)
// eslint-disable-next-line max-len
.replace('<body>', `<body style="background-color:${prop('background-color')};color:${prop('color')}"><header><h1>${subject}</h1><time>${encodeHtml(m ? m.format('LLL') : '')}</time><div>${encodeHtml(this.fromToLine())}</div><div>${encodeHtml(i18n('GLOBAL/TO'))}: ${encodeHtml(this.toToLine())}</div>${cc}</header><${mode}>${this.bodyAsHTML()}</${mode}>`)
.replace('<body>', `<body style="background-color:${prop('background-color')};color:${prop('color')}"><header><h1>${subject}</h1><time>${encodeHtml(m ? m.format('LLL',0,LanguageStore.hourCycle()) : '')}</time><div>${encodeHtml(this.fromToLine())}</div><div>${encodeHtml(i18n('GLOBAL/TO'))}: ${encodeHtml(this.toToLine())}</div>${cc}</header><${mode}>${this.bodyAsHTML()}</${mode}>`)
);
sdoc.close();

View file

@ -30,6 +30,7 @@ export class UserSettingsGeneral extends AbstractViewSettings {
this.language = LanguageStore.language;
this.languages = LanguageStore.languages;
this.hourCycle = LanguageStore.hourCycle;
this.soundNotification = SMAudio.notifications;
this.notificationSound = ko.observable(SettingsGet('NotificationSound'));
@ -115,6 +116,9 @@ export class UserSettingsGeneral extends AbstractViewSettings {
.then(() => Remote.saveSetting('Language', value));
},
hourCycle: value =>
Remote.saveSetting('hourCycle', value),
removeColors: value => {
let dom = MessageUserStore.bodiesDom();
if (dom) {

View file

@ -6,11 +6,13 @@ export const LanguageStore = {
language: ko.observable(''),
languages: ko.observableArray(),
userLanguage: ko.observable(''),
hourCycle: ko.observable(''),
populate: function() {
const aLanguages = Settings.app('languages');
this.languages(isArray(aLanguages) ? aLanguages : []);
this.language(SettingsGet('Language'));
this.userLanguage(SettingsGet('UserLanguage'));
this.hourCycle(SettingsGet('hourCycle'));
}
}

33
dev/prototype.js vendored
View file

@ -7,12 +7,20 @@
Date.defineRelativeTimeFormat = config => relativeTime = config;
// full = Monday, December 12, 2022 at 12:16:21 PM Central European Standard Time
// long = December 12, 2022 at 12:16:21 PM GMT+1
// medium = Dec 12, 2022, 12:16:21 PM
// short = 12/12/22, 12:16 PM
let formats = {
LT : {hour: 'numeric', minute: 'numeric'},
LT : {timeStyle: 'short'},
// LT : {hour: 'numeric', minute: 'numeric'},
L : {},
LL : {year: 'numeric', month: 'short', day: 'numeric'},
LLL : {year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric'},
LLLL : {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric'},
LL : {dateStyle: 'medium'},
// LL : {year: 'numeric', month: 'short', day: 'numeric'},
LLL : {dateStyle: 'long', timeStyle: 'short'},
// LLL : {year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric'},
LLLL : {dateStyle: 'full', timeStyle: 'short'},
// LLLL : {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric'},
'd M': {day: '2-digit', month: 'short'}
},
phpFormats = {
@ -31,11 +39,15 @@
y: {year: '2-digit'},
// Time
A: {hour12: true},
G: {hour: 'numeric'},
H: {hour: '2-digit'},
// A: {hourCycle: 'h12'}, // h11, h12, h23, h24
g: {hour: 'numeric', hourCycle:'h11'},
G: {hour: 'numeric', hourCycle:'h23'},
h: {hour: '2-digit', hourCycle:'h11'},
H: {hour: '2-digit', hourCycle:'h23'},
i: {minute: '2-digit'},
s: {second: '2-digit'},
u: {fractionalSecondDigits: 3},
u: {fractionalSecondDigits: 6},
v: {fractionalSecondDigits: 3},
Z: {timeZone: 'UTC'}
},
relativeTime = {
@ -45,7 +57,7 @@
// Format momentjs/PHP date formats to Intl.DateTimeFormat
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat
Date.prototype.format = function (options, UTC) {
Date.prototype.format = function (options, UTC, hourCycle) {
if (typeof options == 'string') {
if ('Y-m-d\\TH:i:s' == options) {
return this.getFullYear() + '-' + pad2(1 + this.getMonth()) + '-' + pad2(this.getDate())
@ -58,12 +70,15 @@
console.log('Date.format('+s+')');
options = {};
while (i--) {
o = phpFormats[s[i]] || phpFormats[s[i].toUpperCase()];
o = phpFormats[s[i]];
o && Object.entries(o).forEach(([k,v])=>options[k]=v);
}
formats[s] = options;
}
}
if (hourCycle) {
options.hourCycle = hourCycle;
}
return new Intl.DateTimeFormat(doc.documentElement.lang, options).format(this);
};