MOBILE-3565 services: Fix time utils linting
parent
805fc8899d
commit
426540ce49
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import * as moment from 'moment';
|
import moment, { LongDateFormatKey } from 'moment';
|
||||||
import { CoreConstants } from '@core/constants';
|
import { CoreConstants } from '@core/constants';
|
||||||
import { makeSingleton, Translate } from '@singletons/core.singletons';
|
import { makeSingleton, Translate } from '@singletons/core.singletons';
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ import { makeSingleton, Translate } from '@singletons/core.singletons';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CoreTimeUtilsProvider {
|
export class CoreTimeUtilsProvider {
|
||||||
|
|
||||||
protected FORMAT_REPLACEMENTS = { // To convert PHP strf format to Moment format.
|
protected static readonly FORMAT_REPLACEMENTS = { // To convert PHP strf format to Moment format.
|
||||||
'%a': 'ddd',
|
'%a': 'ddd',
|
||||||
'%A': 'dddd',
|
'%A': 'dddd',
|
||||||
'%d': 'DD',
|
'%d': 'DD',
|
||||||
|
@ -65,7 +65,7 @@ export class CoreTimeUtilsProvider {
|
||||||
'%x': 'L',
|
'%x': 'L',
|
||||||
'%n': '\n',
|
'%n': '\n',
|
||||||
'%t': '\t',
|
'%t': '\t',
|
||||||
'%%': '%'
|
'%%': '%',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,7 +97,8 @@ export class CoreTimeUtilsProvider {
|
||||||
converted += ']';
|
converted += ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
converted += typeof this.FORMAT_REPLACEMENTS[char] != 'undefined' ? this.FORMAT_REPLACEMENTS[char] : char;
|
converted += typeof CoreTimeUtilsProvider.FORMAT_REPLACEMENTS[char] != 'undefined' ?
|
||||||
|
CoreTimeUtilsProvider.FORMAT_REPLACEMENTS[char] : char;
|
||||||
} else {
|
} else {
|
||||||
// Not a PHP format. We need to escape them, otherwise the letters could be confused with Moment formats.
|
// Not a PHP format. We need to escape them, otherwise the letters could be confused with Moment formats.
|
||||||
if (!escaping) {
|
if (!escaping) {
|
||||||
|
@ -129,7 +130,7 @@ export class CoreTimeUtilsProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The component ion-datetime doesn't support escaping characters ([]), so we remove them.
|
// The component ion-datetime doesn't support escaping characters ([]), so we remove them.
|
||||||
let fixed = format.replace(/[\[\]]/g, '');
|
let fixed = format.replace(/[[\]]/g, '');
|
||||||
|
|
||||||
if (fixed.indexOf('A') != -1) {
|
if (fixed.indexOf('A') != -1) {
|
||||||
// Do not use am/pm format because there is a bug in ion-datetime.
|
// Do not use am/pm format because there is a bug in ion-datetime.
|
||||||
|
@ -250,7 +251,6 @@ export class CoreTimeUtilsProvider {
|
||||||
* @return Duration in a short human readable format.
|
* @return Duration in a short human readable format.
|
||||||
*/
|
*/
|
||||||
formatDurationShort(duration: number): string {
|
formatDurationShort(duration: number): string {
|
||||||
|
|
||||||
const minutes = Math.floor(duration / 60);
|
const minutes = Math.floor(duration / 60);
|
||||||
const seconds = duration - minutes * 60;
|
const seconds = duration - minutes * 60;
|
||||||
const durations = [];
|
const durations = [];
|
||||||
|
@ -346,7 +346,7 @@ export class CoreTimeUtilsProvider {
|
||||||
* @param localizedFormat Format to use.
|
* @param localizedFormat Format to use.
|
||||||
* @return Localized ISO format
|
* @return Localized ISO format
|
||||||
*/
|
*/
|
||||||
getLocalizedDateFormat(localizedFormat: any): string {
|
getLocalizedDateFormat(localizedFormat: LongDateFormatKey): string {
|
||||||
return moment.localeData().longDateFormat(localizedFormat);
|
return moment.localeData().longDateFormat(localizedFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,6 +366,7 @@ export class CoreTimeUtilsProvider {
|
||||||
return moment().startOf('day').unix();
|
return moment().startOf('day').unix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CoreTimeUtils extends makeSingleton(CoreTimeUtilsProvider) {}
|
export class CoreTimeUtils extends makeSingleton(CoreTimeUtilsProvider) {}
|
||||||
|
|
Loading…
Reference in New Issue