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() {
cd "${BUILD_DIR}/${PKGNAME}/resources/js"
cat _vendor/moment-with-locales.min.js \
ThemeUtils.js \
cat ThemeUtils.js \
bootstrap.js > bundle.js
}

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

@ -26,9 +26,7 @@
*/
let localized_invalid_date = null,
time_language = null,
time_format = null,
let time_language = null,
_ThemeUtils = null;
@ -46,9 +44,6 @@ class ThemeUtils {
return _ThemeUtils;
}
moment.locale( window.navigator.languages );
localized_invalid_date = moment('today', '!@#');
_ThemeUtils = instance;
}
@ -122,36 +117,60 @@ class ThemeUtils {
}
/**
* Get the current time in a localized format. Time format and language are auto-detected
* by default, but can be set manually in the greeter config file.
* Get the current date 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.
* * 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() {
if ( null === time_language ) {
let config = greeter_config.greeter,
manual_language = ( '' !== config.time_language && 'auto' !== config.time_language ),
manual_time_format = ( '' !== config.time_format && 'auto' !== config.time_format );
get_current_localized_date() {
let config = greeter_config.greeter
time_language = manual_language ? config.time_language : window.navigator.language;
time_format = manual_time_format ? config.time_format : 'LT';
var locale = []
if ( manual_language ) {
moment.locale( time_language );
if (time_language === null) {
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 ) {
local_time = moment().format( 'LT' );
return date
}
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
* @memberOf window
*/
const _ready_event = new Event( 'GreeterReady' );
window._ready_event = new Event( 'GreeterReady' );
function channel_ready_cb( channel ) {
_channel = channel;

Loading…
Cancel
Save