mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-24 12:49:19 +00:00
Compute state display tests (#643)
* Move computeDomain and format functions to js * Add tests for computeStateDisplay * Always recalculate state display * Remove LANGUAGE from hassUtils object * Move AppLocalizeBehavior import to mixins * Import mixins to state-card-display * Safety check on computeStateDisplay * Don't store computed domains on stateObj * Integration tests for state-card-display * Include extractDomain code in polymer repo * Remove util function null checking * Dont render test element without hass and stateObj * Revert "Don't store computed domains on stateObj" This reverts commite3509d7182. * Revert "Always recalculate state display" This reverts commit27c24e2694.
This commit is contained in:
committed by
Paulus Schoutsen
parent
7e77a7c32c
commit
3412edb843
22
js/common/util/format_date_time.js
Normal file
22
js/common/util/format_date_time.js
Normal file
@@ -0,0 +1,22 @@
|
||||
// Check for support of native locale string options
|
||||
function toLocaleStringSupportsOptions() {
|
||||
try {
|
||||
new Date().toLocaleString('i');
|
||||
} catch (e) {
|
||||
return e.name === 'RangeError';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export default (toLocaleStringSupportsOptions() ?
|
||||
function (dateObj, locales) {
|
||||
return dateObj.toLocaleString(locales, {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
hour: 'numeric',
|
||||
minute: '2-digit',
|
||||
});
|
||||
} : function (dateObj, locales) { // eslint-disable-line no-unused-vars
|
||||
return window.fecha.format(dateObj, 'haDateTime');
|
||||
});
|
||||
Reference in New Issue
Block a user