Browse Source

Removed moment.js, updated to Intl

sisyphus
JezerM 4 years ago
parent
commit
ecb0129133
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 3
      build/utils.sh
  2. 71
      web-greeter/resources/js/ThemeUtils.js
  3. 1217
      web-greeter/resources/js/_vendor/moment-with-locales.min.js
  4. 2
      web-greeter/resources/js/bootstrap.js

3
build/utils.sh

@ -14,8 +14,7 @@ clean_build_dir() {
combine_javascript_sources() { combine_javascript_sources() {
cd "${BUILD_DIR}/${PKGNAME}/resources/js" cd "${BUILD_DIR}/${PKGNAME}/resources/js"
cat _vendor/moment-with-locales.min.js \ cat ThemeUtils.js \
ThemeUtils.js \
bootstrap.js > bundle.js bootstrap.js > bundle.js
} }

71
web-greeter/resources/js/ThemeUtils.js

@ -26,9 +26,7 @@
*/ */
let localized_invalid_date = null, let time_language = null,
time_language = null,
time_format = null,
_ThemeUtils = null; _ThemeUtils = null;
@ -46,9 +44,6 @@ class ThemeUtils {
return _ThemeUtils; return _ThemeUtils;
} }
moment.locale( window.navigator.languages );
localized_invalid_date = moment('today', '!@#');
_ThemeUtils = instance; _ThemeUtils = instance;
} }
@ -122,36 +117,60 @@ class ThemeUtils {
} }
/** /**
* Get the current time in a localized format. Time format and language are auto-detected * Get the current date in a localized format. Local language is autodetected by default, but can be set manually in the greeter config file.
* by default, but can be set manually in the greeter config file.
* * `language` defaults to the system's language, but can be set manually in the config file. * * `language` defaults to the system's language, but can be set manually in the config file.
* * When `time_format` config file option has a valid value, time will be formatted
* according to that value.
* * When `time_format` does not have a valid value, the time format will be `LT`
* which is `1:00 PM` or `13:00` depending on the system's locale.
* *
* @return {string} The current localized time. * @returns {Object} The current date.
*/ */
get_current_localized_time() { get_current_localized_date() {
if ( null === time_language ) { let config = greeter_config.greeter
let config = greeter_config.greeter,
manual_language = ( '' !== config.time_language && 'auto' !== config.time_language ),
manual_time_format = ( '' !== config.time_format && 'auto' !== config.time_format );
time_language = manual_language ? config.time_language : window.navigator.language; var locale = []
time_format = manual_time_format ? config.time_format : 'LT';
if ( manual_language ) { if (time_language === null) {
moment.locale( time_language ); time_language = config.time_language
} }
if (time_language != "") {
locale.push(time_language)
} }
let local_time = moment().format( time_format ); let optionsDate = { day: "2-digit", month: "2-digit", year: "2-digit" }
let fmtDate = Intl.DateTimeFormat(locale, optionsDate)
let now = new Date()
var date = fmtDate.format(now)
if ( local_time === localized_invalid_date ) { return date
local_time = moment().format( 'LT' );
} }
return local_time; /**
* Get the current time in a localized format. Local language is autodetected by default, but can be set manually in the greeter config file.
* * `language` defaults to the system's language, but can be set manually in the config file.
*
* @returns {Object} The current time.
*/
get_current_localized_time() {
let config = greeter_config.greeter
var locale = []
if (time_language === null) {
time_language = config.time_language
}
if (time_language != "") {
locale.push(time_language)
}
let optionsTime = { hour: "2-digit", minute: "2-digit" }
let fmtTime = Intl.DateTimeFormat(locale, optionsTime)
let now = new Date()
var time = fmtTime.format(now)
return time
} }
} }

1217
web-greeter/resources/js/_vendor/moment-with-locales.min.js vendored

File diff suppressed because it is too large Load Diff

2
web-greeter/resources/js/bootstrap.js vendored

@ -36,7 +36,7 @@
* @type Event * @type Event
* @memberOf window * @memberOf window
*/ */
const _ready_event = new Event( 'GreeterReady' ); window._ready_event = new Event( 'GreeterReady' );
function channel_ready_cb( channel ) { function channel_ready_cb( channel ) {
_channel = channel; _channel = channel;

Loading…
Cancel
Save