mirror of https://github.com/keeweb/keeweb
Merge branch 'MrSnix-feature/time-format' into develop
commit
1ef5ffab52
|
@ -2,7 +2,7 @@
|
|||
import kdbxweb from 'kdbxweb';
|
||||
import { RuntimeInfo } from 'const/runtime-info';
|
||||
import { Links } from 'const/links';
|
||||
import { DateFormat } from 'util/formatting/date-format';
|
||||
import { DateFormat } from 'comp/i18n/date-format';
|
||||
import { StringFormat } from 'util/formatting/string-format';
|
||||
import { Locale } from 'util/locale';
|
||||
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
import { SettingsManager } from 'comp/settings/settings-manager';
|
||||
import { StringFormat } from 'util/formatting/string-format';
|
||||
|
||||
const DateFormat = {
|
||||
months() {
|
||||
const format = new Intl.DateTimeFormat(SettingsManager.activeLocale, { month: 'long' });
|
||||
const months = [];
|
||||
for (let month = 0; month < 12; month++) {
|
||||
months.push(format.format(new Date(2008, month)));
|
||||
}
|
||||
return months;
|
||||
},
|
||||
|
||||
weekDays() {
|
||||
const format = new Intl.DateTimeFormat(SettingsManager.activeLocale, { weekday: 'long' });
|
||||
const weekdays = [];
|
||||
for (let day = 1; day < 8; day++) {
|
||||
weekdays.push(format.format(new Date(2007, 9, 6 + day)));
|
||||
}
|
||||
return weekdays;
|
||||
},
|
||||
|
||||
shortWeekDays() {
|
||||
const format = new Intl.DateTimeFormat(SettingsManager.activeLocale, { weekday: 'short' });
|
||||
const weekdays = [];
|
||||
for (let day = 1; day < 8; day++) {
|
||||
weekdays.push(format.format(new Date(Date.UTC(2007, 9, 6 + day))));
|
||||
}
|
||||
return weekdays;
|
||||
},
|
||||
|
||||
dtStr(dt) {
|
||||
if (typeof dt === 'number') {
|
||||
dt = new Date(dt);
|
||||
}
|
||||
return dt
|
||||
? new Intl.DateTimeFormat(SettingsManager.activeLocale, {
|
||||
dateStyle: 'medium',
|
||||
timeStyle: 'medium'
|
||||
}).format(dt)
|
||||
: '';
|
||||
},
|
||||
|
||||
dStr(dt) {
|
||||
if (typeof dt === 'number') {
|
||||
dt = new Date(dt);
|
||||
}
|
||||
return dt
|
||||
? new Intl.DateTimeFormat(SettingsManager.activeLocale, {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
}).format(dt)
|
||||
: '';
|
||||
},
|
||||
|
||||
dtStrFs(dt) {
|
||||
if (typeof dt === 'number') {
|
||||
dt = new Date(dt);
|
||||
}
|
||||
return dt
|
||||
? dt.getFullYear() +
|
||||
'-' +
|
||||
StringFormat.pad(dt.getMonth() + 1, 2) +
|
||||
'-' +
|
||||
StringFormat.pad(dt.getDate(), 2) +
|
||||
'T' +
|
||||
StringFormat.pad(dt.getHours(), 2) +
|
||||
'-' +
|
||||
StringFormat.pad(dt.getMinutes(), 2) +
|
||||
'-' +
|
||||
StringFormat.pad(dt.getSeconds(), 2)
|
||||
: '';
|
||||
}
|
||||
};
|
||||
|
||||
export { DateFormat };
|
|
@ -1,35 +1,4 @@
|
|||
{
|
||||
"months": [
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"
|
||||
],
|
||||
"monthsShort": [
|
||||
"Jan",
|
||||
"Feb",
|
||||
"Mar",
|
||||
"Apr",
|
||||
"May",
|
||||
"Jun",
|
||||
"Jul",
|
||||
"Aug",
|
||||
"Sep",
|
||||
"Oct",
|
||||
"Nov",
|
||||
"Dec"
|
||||
],
|
||||
"weekdays": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
||||
"weekdaysShort": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
||||
|
||||
"retToApp": "return to app",
|
||||
"name": "name",
|
||||
"icon": "icon",
|
||||
|
|
|
@ -16,7 +16,7 @@ import { YubiKeyOtpModel } from 'models/external/yubikey-otp-model';
|
|||
import { MenuModel } from 'models/menu/menu-model';
|
||||
import { PluginManager } from 'plugins/plugin-manager';
|
||||
import { Features } from 'util/features';
|
||||
import { DateFormat } from 'util/formatting/date-format';
|
||||
import { DateFormat } from 'comp/i18n/date-format';
|
||||
import { UrlFormat } from 'util/formatting/url-format';
|
||||
import { IdGenerator } from 'util/generators/id-generator';
|
||||
import { Locale } from 'util/locale';
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { DateFormat } from 'util/formatting/date-format';
|
||||
import { DateFormat } from 'comp/i18n/date-format';
|
||||
import { Locale } from 'util/locale';
|
||||
|
||||
const EntryPresenter = function (descField, noColor, activeEntryId) {
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
import { StringFormat } from 'util/formatting/string-format';
|
||||
import { Locale } from 'util/locale';
|
||||
|
||||
const DateFormat = {
|
||||
dtStr(dt) {
|
||||
if (typeof dt === 'number') {
|
||||
dt = new Date(dt);
|
||||
}
|
||||
return dt
|
||||
? this.dStr(dt) +
|
||||
' ' +
|
||||
StringFormat.pad(dt.getHours(), 2) +
|
||||
':' +
|
||||
StringFormat.pad(dt.getMinutes(), 2) +
|
||||
':' +
|
||||
StringFormat.pad(dt.getSeconds(), 2)
|
||||
: '';
|
||||
},
|
||||
|
||||
dStr(dt) {
|
||||
if (typeof dt === 'number') {
|
||||
dt = new Date(dt);
|
||||
}
|
||||
return dt
|
||||
? dt.getDate() + ' ' + Locale.monthsShort[dt.getMonth()] + ' ' + dt.getFullYear()
|
||||
: '';
|
||||
},
|
||||
|
||||
dtStrFs(dt) {
|
||||
if (typeof dt === 'number') {
|
||||
dt = new Date(dt);
|
||||
}
|
||||
return dt
|
||||
? dt.getFullYear() +
|
||||
'-' +
|
||||
StringFormat.pad(dt.getMonth() + 1, 2) +
|
||||
'-' +
|
||||
StringFormat.pad(dt.getDate(), 2) +
|
||||
'T' +
|
||||
StringFormat.pad(dt.getHours(), 2) +
|
||||
'-' +
|
||||
StringFormat.pad(dt.getMinutes(), 2) +
|
||||
'-' +
|
||||
StringFormat.pad(dt.getSeconds(), 2)
|
||||
: '';
|
||||
}
|
||||
};
|
||||
|
||||
export { DateFormat };
|
|
@ -1,6 +1,6 @@
|
|||
import { Locale } from 'util/locale';
|
||||
import { StringFormat } from 'util/formatting/string-format';
|
||||
import { DateFormat } from 'util/formatting/date-format';
|
||||
import { DateFormat } from 'comp/i18n/date-format';
|
||||
import { AppModel } from 'models/app-model';
|
||||
import { FieldViewReadOnly } from 'views/fields/field-view-read-only';
|
||||
import { FieldViewOtp } from 'views/fields/field-view-otp';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { View } from 'framework/views/view';
|
||||
import { Alerts } from 'comp/ui/alerts';
|
||||
import { Keys } from 'const/keys';
|
||||
import { DateFormat } from 'util/formatting/date-format';
|
||||
import { DateFormat } from 'comp/i18n/date-format';
|
||||
import { StringFormat } from 'util/formatting/string-format';
|
||||
import { Locale } from 'util/locale';
|
||||
import { Copyable } from 'framework/views/copyable';
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import Pikaday from 'pikaday';
|
||||
import { DateFormat } from 'util/formatting/date-format';
|
||||
import { Locale } from 'util/locale';
|
||||
import { DateFormat } from 'comp/i18n/date-format';
|
||||
import { FieldViewText } from 'views/fields/field-view-text';
|
||||
|
||||
class FieldViewDate extends FieldViewText {
|
||||
|
@ -30,9 +29,9 @@ class FieldViewDate extends FieldViewText {
|
|||
i18n: {
|
||||
previousMonth: '',
|
||||
nextMonth: '',
|
||||
months: Locale.months,
|
||||
weekdays: Locale.weekdays,
|
||||
weekdaysShort: Locale.weekdaysShort
|
||||
months: DateFormat.months(),
|
||||
weekdays: DateFormat.weekDays(),
|
||||
weekdaysShort: DateFormat.shortWeekDays()
|
||||
}
|
||||
});
|
||||
this.picker.adjustPosition = this.adjustPickerPosition.bind(this);
|
||||
|
|
|
@ -8,7 +8,7 @@ import { YubiKey } from 'comp/app/yubikey';
|
|||
import { UsbListener } from 'comp/app/usb-listener';
|
||||
import { Links } from 'const/links';
|
||||
import { AppSettingsModel } from 'models/app-settings-model';
|
||||
import { DateFormat } from 'util/formatting/date-format';
|
||||
import { DateFormat } from 'comp/i18n/date-format';
|
||||
import { UrlFormat } from 'util/formatting/url-format';
|
||||
import { PasswordPresenter } from 'util/formatting/password-presenter';
|
||||
import { Locale } from 'util/locale';
|
||||
|
|
|
@ -12,7 +12,7 @@ import { AppSettingsModel } from 'models/app-settings-model';
|
|||
import { UpdateModel } from 'models/update-model';
|
||||
import { SemVer } from 'util/data/semver';
|
||||
import { Features } from 'util/features';
|
||||
import { DateFormat } from 'util/formatting/date-format';
|
||||
import { DateFormat } from 'comp/i18n/date-format';
|
||||
import { Locale } from 'util/locale';
|
||||
import { SettingsLogsView } from 'views/settings/settings-logs-view';
|
||||
import { SettingsPrvView } from 'views/settings/settings-prv-view';
|
||||
|
|
|
@ -10,7 +10,7 @@ import { PluginManager } from 'plugins/plugin-manager';
|
|||
import { Comparators } from 'util/data/comparators';
|
||||
import { SemVer } from 'util/data/semver';
|
||||
import { Features } from 'util/features';
|
||||
import { DateFormat } from 'util/formatting/date-format';
|
||||
import { DateFormat } from 'comp/i18n/date-format';
|
||||
import { Locale } from 'util/locale';
|
||||
import template from 'templates/settings/settings-plugins.hbs';
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
import { expect } from 'chai';
|
||||
import { DateFormat } from 'comp/i18n/date-format';
|
||||
|
||||
describe('DateFormat', () => {
|
||||
const dt = new Date(2020, 0, 2, 3, 4, 5, 6);
|
||||
|
||||
it('should return months', () => {
|
||||
expect(DateFormat.months()).to.eql([
|
||||
'January',
|
||||
'February',
|
||||
'March',
|
||||
'April',
|
||||
'May',
|
||||
'June',
|
||||
'July',
|
||||
'August',
|
||||
'September',
|
||||
'October',
|
||||
'November',
|
||||
'December'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return week days', () => {
|
||||
expect(DateFormat.weekDays()).to.eql([
|
||||
'Sunday',
|
||||
'Monday',
|
||||
'Tuesday',
|
||||
'Wednesday',
|
||||
'Thursday',
|
||||
'Friday',
|
||||
'Saturday'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return short week days', () => {
|
||||
expect(DateFormat.shortWeekDays()).to.eql([
|
||||
'Sun',
|
||||
'Mon',
|
||||
'Tue',
|
||||
'Wed',
|
||||
'Thu',
|
||||
'Fri',
|
||||
'Sat'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should format date', () => {
|
||||
expect(DateFormat.dStr(dt)).to.eql('Jan 2, 2020');
|
||||
});
|
||||
|
||||
it('should format date and time', () => {
|
||||
expect(DateFormat.dtStr(dt)).to.eql('Jan 2, 2020, 3:04:05 AM');
|
||||
});
|
||||
|
||||
it('should format date and time in sortable format', () => {
|
||||
expect(DateFormat.dtStrFs(dt)).to.eql('2020-01-02T03-04-05');
|
||||
});
|
||||
});
|
|
@ -1,18 +0,0 @@
|
|||
import { expect } from 'chai';
|
||||
import { DateFormat } from 'util/formatting/date-format';
|
||||
|
||||
describe('DateFormat', () => {
|
||||
const dt = new Date(2020, 0, 2, 3, 4, 5, 6);
|
||||
|
||||
it('should format date', () => {
|
||||
expect(DateFormat.dStr(dt)).to.eql('2 Jan 2020');
|
||||
});
|
||||
|
||||
it('should format date and time', () => {
|
||||
expect(DateFormat.dtStr(dt)).to.eql('2 Jan 2020 03:04:05');
|
||||
});
|
||||
|
||||
it('should format date and time in sortable format', () => {
|
||||
expect(DateFormat.dtStrFs(dt)).to.eql('2020-01-02T03-04-05');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue