This commit is contained in:
Mo Bitar
2020-01-31 10:45:59 -06:00
parent 53f6b82dd6
commit 05fd5e7756
8 changed files with 74 additions and 111 deletions

View File

@@ -47,7 +47,7 @@ import {
SyncResolutionMenu
} from './directives/views';
import { appDate, appDateTime, trusted } from './filters';
import { trusted } from './filters';
import {
ActionsManager,
@@ -136,8 +136,6 @@ angular
// Filters
angular
.module('app')
.filter('appDate', appDate)
.filter('appDateTime', appDateTime)
.filter('trusted', ['$sce', trusted]);
// Services

View File

@@ -1,4 +1,5 @@
import { PrivilegesManager } from '@/services/privilegesManager';
import { dateToLocalizedString } from '@/utils';
import template from '%/footer.pug';
import {
APP_STATE_EVENT_EDITOR_FOCUSED,
@@ -268,7 +269,7 @@ class FooterCtrl {
}
syncUpdated() {
this.lastSyncDate = new Date();
this.lastSyncDate = dateToLocalizedString(new Date());
}
onNewUpdateAvailable() {

View File

@@ -1,33 +0,0 @@
// reuse
var locale, formatter;
/* @ngInject */
export function appDate($filter) {
return function(input) {
return input ? $filter('date')(new Date(input), 'MM/dd/yyyy', 'UTC') : '';
};
}
/* @ngInject */
export function appDateTime($filter) {
return function(input) {
if (typeof Intl !== 'undefined' && Intl.DateTimeFormat) {
if (!formatter) {
locale =
navigator.languages && navigator.languages.length
? navigator.languages[0]
: navigator.language;
formatter = new Intl.DateTimeFormat(locale, {
year: 'numeric',
month: 'numeric',
day: '2-digit',
hour: '2-digit',
minute: '2-digit'
});
}
return formatter.format(input);
} else {
return input ? $filter('date')(new Date(input), 'MM/dd/yyyy h:mm a') : '';
}
};
}

View File

@@ -1,2 +1 @@
export { appDate, appDateTime } from './appDate';
export { trusted } from './trusted';

View File

@@ -39,9 +39,35 @@ export function getPlatformString() {
}
}
let sharedDateFormatter;
export function dateToLocalizedString(date) {
if (typeof Intl !== 'undefined' && Intl.DateTimeFormat) {
if (!sharedDateFormatter) {
const locale = (
(navigator.languages && navigator.languages.length)
? navigator.languages[0]
: navigator.language
);
sharedDateFormatter = new Intl.DateTimeFormat(locale, {
year: 'numeric',
month: 'numeric',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
});
}
return sharedDateFormatter.format(date);
} else {
// IE < 11, Safari <= 9.0.
// In English, this generates the string most similar to
// the toLocaleDateString() result above.
return date.toDateString() + ' ' + date.toLocaleTimeString();
}
}
/** Via https://davidwalsh.name/javascript-debounce-function */
export function debounce(func, wait, immediate) {
var timeout;
let timeout;
return function () {
const context = this;
const args = arguments;

View File

@@ -52,7 +52,7 @@
ng-if='ctrl.lastSyncDate && !ctrl.isRefreshing'
)
.sk-label.subtle
| Last refreshed {{ctrl.lastSyncDate | appDateTime}}
| Last refreshed {{ctrl.lastSyncDate}}
.sk-app-bar-item(
ng-click='ctrl.toggleSyncResolutionMenu()',
ng-if='(ctrl.outOfSync && !ctrl.isRefreshing) || ctrl.showSyncResolution'

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long