mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
All: Added option to set date and time format
This commit is contained in:
parent
6e23fead59
commit
f9f5974267
@ -2,6 +2,7 @@ const React = require('react');
|
|||||||
const { connect } = require('react-redux');
|
const { connect } = require('react-redux');
|
||||||
const { _ } = require('lib/locale.js');
|
const { _ } = require('lib/locale.js');
|
||||||
const { themeStyle } = require('../theme.js');
|
const { themeStyle } = require('../theme.js');
|
||||||
|
const { time } = require('lib/time-utils.js');
|
||||||
const Datetime = require('react-datetime');
|
const Datetime = require('react-datetime');
|
||||||
|
|
||||||
class PromptDialog extends React.Component {
|
class PromptDialog extends React.Component {
|
||||||
@ -106,8 +107,8 @@ class PromptDialog extends React.Component {
|
|||||||
if (this.props.inputType === 'datetime') {
|
if (this.props.inputType === 'datetime') {
|
||||||
inputComp = <Datetime
|
inputComp = <Datetime
|
||||||
value={this.state.answer}
|
value={this.state.answer}
|
||||||
dateFormat="DD/MM/YYYY"
|
dateFormat={time.dateFormat()}
|
||||||
timeFormat="HH:mm"
|
timeFormat={time.timeFormat()}
|
||||||
onChange={(momentObject) => onDateTimeChange(momentObject)}
|
onChange={(momentObject) => onDateTimeChange(momentObject)}
|
||||||
/>
|
/>
|
||||||
} else {
|
} else {
|
||||||
|
@ -14,6 +14,7 @@ const { Logger } = require('lib/logger.js');
|
|||||||
const { splitCommandString } = require('lib/string-utils.js');
|
const { splitCommandString } = require('lib/string-utils.js');
|
||||||
const { sprintf } = require('sprintf-js');
|
const { sprintf } = require('sprintf-js');
|
||||||
const { reg } = require('lib/registry.js');
|
const { reg } = require('lib/registry.js');
|
||||||
|
const { time } = require('lib/time-utils.js');
|
||||||
const BaseSyncTarget = require('lib/BaseSyncTarget.js');
|
const BaseSyncTarget = require('lib/BaseSyncTarget.js');
|
||||||
const { fileExtension } = require('lib/path-utils.js');
|
const { fileExtension } = require('lib/path-utils.js');
|
||||||
const { shim } = require('lib/shim.js');
|
const { shim } = require('lib/shim.js');
|
||||||
@ -250,6 +251,11 @@ class BaseApplication {
|
|||||||
await this.refreshNotes(newState);
|
await this.refreshNotes(newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((action.type == 'SETTING_UPDATE_ONE' && (action.key == 'dateFormat' || action.key == 'timeFormat')) || (action.type == 'SETTING_UPDATE_ALL')) {
|
||||||
|
time.setDateFormat(Setting.value('dateFormat'));
|
||||||
|
time.setTimeFormat(Setting.value('timeFormat'));
|
||||||
|
}
|
||||||
|
|
||||||
if (action.type == 'TAG_SELECT' || action.type === 'TAG_DELETE') {
|
if (action.type == 'TAG_SELECT' || action.type === 'TAG_DELETE') {
|
||||||
await this.refreshNotes(newState);
|
await this.refreshNotes(newState);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ const { BaseModel } = require('lib/base-model.js');
|
|||||||
const { Database } = require('lib/database.js');
|
const { Database } = require('lib/database.js');
|
||||||
const { Logger } = require('lib/logger.js');
|
const { Logger } = require('lib/logger.js');
|
||||||
const SyncTargetRegistry = require('lib/SyncTargetRegistry.js');
|
const SyncTargetRegistry = require('lib/SyncTargetRegistry.js');
|
||||||
|
const { time } = require('lib/time-utils.js');
|
||||||
const { sprintf } = require('sprintf-js');
|
const { sprintf } = require('sprintf-js');
|
||||||
const { _, supportedLocalesToLanguages, defaultLocale } = require('lib/locale.js');
|
const { _, supportedLocalesToLanguages, defaultLocale } = require('lib/locale.js');
|
||||||
|
|
||||||
@ -34,6 +35,23 @@ class Setting extends BaseModel {
|
|||||||
'locale': { value: defaultLocale(), type: Setting.TYPE_STRING, isEnum: true, public: true, label: () => _('Language'), options: () => {
|
'locale': { value: defaultLocale(), type: Setting.TYPE_STRING, isEnum: true, public: true, label: () => _('Language'), options: () => {
|
||||||
return supportedLocalesToLanguages();
|
return supportedLocalesToLanguages();
|
||||||
}},
|
}},
|
||||||
|
'dateFormat': { value: Setting.DATE_FORMAT_1, type: Setting.TYPE_STRING, isEnum: true, public: true, label: () => _('Date format'), options: () => {
|
||||||
|
let options = {}
|
||||||
|
const now = (new Date('2017-01-30T12:00:00')).getTime();
|
||||||
|
options[Setting.DATE_FORMAT_1] = time.formatMsToLocal(now, Setting.DATE_FORMAT_1);
|
||||||
|
options[Setting.DATE_FORMAT_2] = time.formatMsToLocal(now, Setting.DATE_FORMAT_2);
|
||||||
|
options[Setting.DATE_FORMAT_3] = time.formatMsToLocal(now, Setting.DATE_FORMAT_3);
|
||||||
|
options[Setting.DATE_FORMAT_4] = time.formatMsToLocal(now, Setting.DATE_FORMAT_4);
|
||||||
|
options[Setting.DATE_FORMAT_5] = time.formatMsToLocal(now, Setting.DATE_FORMAT_5);
|
||||||
|
return options;
|
||||||
|
}},
|
||||||
|
'timeFormat': { value: Setting.TIME_FORMAT_1, type: Setting.TYPE_STRING, isEnum: true, public: true, label: () => _('Time format'), options: () => {
|
||||||
|
let options = {}
|
||||||
|
const now = (new Date('2017-01-30T20:30:00')).getTime();
|
||||||
|
options[Setting.TIME_FORMAT_1] = time.formatMsToLocal(now, Setting.TIME_FORMAT_1);
|
||||||
|
options[Setting.TIME_FORMAT_2] = time.formatMsToLocal(now, Setting.TIME_FORMAT_2);
|
||||||
|
return options;
|
||||||
|
}},
|
||||||
'theme': { value: Setting.THEME_LIGHT, type: Setting.TYPE_INT, public: true, appTypes: ['mobile'], isEnum: true, label: () => _('Theme'), options: () => {
|
'theme': { value: Setting.THEME_LIGHT, type: Setting.TYPE_INT, public: true, appTypes: ['mobile'], isEnum: true, label: () => _('Theme'), options: () => {
|
||||||
let output = {};
|
let output = {};
|
||||||
output[Setting.THEME_LIGHT] = _('Light');
|
output[Setting.THEME_LIGHT] = _('Light');
|
||||||
@ -398,6 +416,15 @@ Setting.TYPE_OBJECT = 5;
|
|||||||
Setting.THEME_LIGHT = 1;
|
Setting.THEME_LIGHT = 1;
|
||||||
Setting.THEME_DARK = 2;
|
Setting.THEME_DARK = 2;
|
||||||
|
|
||||||
|
Setting.DATE_FORMAT_1 = 'DD/MM/YYYY'
|
||||||
|
Setting.DATE_FORMAT_2 = 'DD/MM/YY';
|
||||||
|
Setting.DATE_FORMAT_3 = 'MM/DD/YYYY';
|
||||||
|
Setting.DATE_FORMAT_4 = 'MM/DD/YY';
|
||||||
|
Setting.DATE_FORMAT_5 = 'YYYY-MM-DD';
|
||||||
|
|
||||||
|
Setting.TIME_FORMAT_1 = 'HH:mm';
|
||||||
|
Setting.TIME_FORMAT_2 = 'h:mm A';
|
||||||
|
|
||||||
// Contains constants that are set by the application and
|
// Contains constants that are set by the application and
|
||||||
// cannot be modified by the user:
|
// cannot be modified by the user:
|
||||||
Setting.constants_ = {
|
Setting.constants_ = {
|
||||||
|
@ -64,8 +64,6 @@ class AlarmService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info('NOTE', note, Note.needAlarm(note));
|
|
||||||
|
|
||||||
if (isDeleted ||
|
if (isDeleted ||
|
||||||
!Note.needAlarm(note) ||
|
!Note.needAlarm(note) ||
|
||||||
(alarm && alarm.trigger_time !== note.todo_due))
|
(alarm && alarm.trigger_time !== note.todo_due))
|
||||||
@ -124,7 +122,6 @@ class AlarmService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: inner notifications (when app is active)
|
// TODO: inner notifications (when app is active)
|
||||||
// TODO: locale-dependent format
|
|
||||||
// TODO: status to view active notifications
|
// TODO: status to view active notifications
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,38 +1,63 @@
|
|||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
|
||||||
let time = {
|
class Time {
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.dateFormat_ = 'DD/MM/YYYY';
|
||||||
|
this.timeFormat_ = 'HH:mm';
|
||||||
|
}
|
||||||
|
|
||||||
|
dateFormat() {
|
||||||
|
return this.dateFormat_;
|
||||||
|
}
|
||||||
|
|
||||||
|
setDateFormat(v) {
|
||||||
|
this.dateFormat_ = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
timeFormat() {
|
||||||
|
return this.timeFormat_;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeFormat(v) {
|
||||||
|
this.timeFormat_ = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
dateTimeFormat() {
|
||||||
|
return this.dateFormat() + ' ' + this.timeFormat();
|
||||||
|
}
|
||||||
|
|
||||||
unix() {
|
unix() {
|
||||||
return Math.floor(Date.now() / 1000);
|
return Math.floor(Date.now() / 1000);
|
||||||
},
|
}
|
||||||
|
|
||||||
unixMs() {
|
unixMs() {
|
||||||
return Date.now();
|
return Date.now();
|
||||||
},
|
}
|
||||||
|
|
||||||
unixMsToObject(ms) {
|
unixMsToObject(ms) {
|
||||||
return new Date(ms);
|
return new Date(ms);
|
||||||
},
|
}
|
||||||
|
|
||||||
unixMsToS(ms) {
|
unixMsToS(ms) {
|
||||||
return Math.floor(ms / 1000);
|
return Math.floor(ms / 1000);
|
||||||
},
|
}
|
||||||
|
|
||||||
unixMsToIso(ms) {
|
unixMsToIso(ms) {
|
||||||
return moment.unix(ms / 1000).utc().format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z';
|
return moment.unix(ms / 1000).utc().format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z';
|
||||||
},
|
}
|
||||||
|
|
||||||
unixMsToIsoSec(ms) {
|
unixMsToIsoSec(ms) {
|
||||||
return moment.unix(ms / 1000).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z';
|
return moment.unix(ms / 1000).utc().format('YYYY-MM-DDTHH:mm:ss') + 'Z';
|
||||||
},
|
}
|
||||||
|
|
||||||
unixMsToLocalDateTime(ms) {
|
unixMsToLocalDateTime(ms) {
|
||||||
return moment.unix(ms / 1000).format('DD/MM/YYYY HH:mm');
|
return moment.unix(ms / 1000).format('DD/MM/YYYY HH:mm');
|
||||||
},
|
}
|
||||||
|
|
||||||
formatMsToLocal(ms, format) {
|
formatMsToLocal(ms, format) {
|
||||||
return moment(ms).format(format);
|
return moment(ms).format(format);
|
||||||
},
|
}
|
||||||
|
|
||||||
msleep(ms) {
|
msleep(ms) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -40,12 +65,14 @@ let time = {
|
|||||||
resolve();
|
resolve();
|
||||||
}, ms);
|
}, ms);
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
sleep(seconds) {
|
sleep(seconds) {
|
||||||
return this.msleep(seconds * 1000);
|
return this.msleep(seconds * 1000);
|
||||||
},
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const time = new Time();
|
||||||
|
|
||||||
module.exports = { time };
|
module.exports = { time };
|
@ -7,6 +7,7 @@ const AlarmServiceDriver = require('lib/services/AlarmServiceDriver');
|
|||||||
const { createStore, applyMiddleware } = require('redux');
|
const { createStore, applyMiddleware } = require('redux');
|
||||||
const { shimInit } = require('lib/shim-init-react.js');
|
const { shimInit } = require('lib/shim-init-react.js');
|
||||||
const { Log } = require('lib/log.js');
|
const { Log } = require('lib/log.js');
|
||||||
|
const { time } = require('lib/time-utils.js');
|
||||||
const { AppNav } = require('lib/components/app-nav.js');
|
const { AppNav } = require('lib/components/app-nav.js');
|
||||||
const { Logger } = require('lib/logger.js');
|
const { Logger } = require('lib/logger.js');
|
||||||
const { Note } = require('lib/models/note.js');
|
const { Note } = require('lib/models/note.js');
|
||||||
@ -63,6 +64,11 @@ const generalMiddleware = store => next => async (action) => {
|
|||||||
reg.setupRecurrentSync();
|
reg.setupRecurrentSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((action.type == 'SETTING_UPDATE_ONE' && (action.key == 'dateFormat' || action.key == 'timeFormat')) || (action.type == 'SETTING_UPDATE_ALL')) {
|
||||||
|
time.setDateFormat(Setting.value('dateFormat'));
|
||||||
|
time.setTimeFormat(Setting.value('timeFormat'));
|
||||||
|
}
|
||||||
|
|
||||||
if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'locale' || action.type == 'SETTING_UPDATE_ALL') {
|
if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'locale' || action.type == 'SETTING_UPDATE_ALL') {
|
||||||
setLocale(Setting.value('locale'));
|
setLocale(Setting.value('locale'));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user