libs/d3/src/lib/helper/d3-time-format-locale.service.ts
This service formats the time labels for the time axis in d3. Internationalisation will be managed by moment.
Properties |
|
Methods |
|
constructor(timezoneSrvc: TimezoneService)
|
||||||
Parameters :
|
Public formatTime | ||||||
formatTime(time: number)
|
||||||
Parameters :
Returns :
string
|
Private roundDay | ||||||
roundDay(time: number)
|
||||||
Parameters :
Returns :
any
|
Private roundHour | ||||||
roundHour(time: number)
|
||||||
Parameters :
Returns :
any
|
Private roundMinute | ||||||
roundMinute(time: number)
|
||||||
Parameters :
Returns :
any
|
Private roundMonth | ||||||
roundMonth(time: number)
|
||||||
Parameters :
Returns :
any
|
Private roundSecond | ||||||
roundSecond(time: number)
|
||||||
Parameters :
Returns :
any
|
Private roundWeek | ||||||
roundWeek(time: number)
|
||||||
Parameters :
Returns :
any
|
Private roundYear | ||||||
roundYear(time: number)
|
||||||
Parameters :
Returns :
any
|
Protected formatDay |
Type : string
|
Default value : 'MMM D'
|
Protected formatHour |
Type : string
|
Default value : 'HH:mm'
|
Protected formatMillisecond |
Type : string
|
Default value : '.SSS'
|
Protected formatMinute |
Type : string
|
Default value : 'HH:mm'
|
Protected formatMonth |
Type : string
|
Default value : 'MMMM'
|
Protected formatSecond |
Type : string
|
Default value : ':ss'
|
Protected formatWeek |
Type : string
|
Default value : 'MMM D'
|
Protected formatYear |
Type : string
|
Default value : 'YYYY'
|
import { Injectable } from '@angular/core';
import { TimezoneService } from '@helgoland/core';
import moment from 'moment';
/**
* This service formats the time labels for the time axis in d3. Internationalisation will be managed by moment.
*/
@Injectable({
providedIn: 'root'
})
export class D3TimeFormatLocaleService {
protected formatMillisecond = '.SSS';
protected formatSecond = ':ss';
protected formatMinute = 'HH:mm';
protected formatHour = 'HH:mm';
protected formatDay = 'MMM D';
protected formatWeek = 'MMM D';
protected formatMonth = 'MMMM';
protected formatYear = 'YYYY';
constructor(
protected timezoneSrvc: TimezoneService
) { }
public formatTime(time: number): string {
const curr = this.timezoneSrvc.createTzDate(time);
const format = this.roundSecond(time) < curr ? this.formatMillisecond
: this.roundMinute(time) < curr ? this.formatSecond
: this.roundHour(time) < curr ? this.formatMinute
: this.roundDay(time) < curr ? this.formatHour
: this.roundMonth(time) < curr ? (this.roundWeek(time) < curr ? this.formatDay : this.formatWeek)
: this.roundYear(time) < curr ? this.formatMonth
: this.formatYear;
return this.timezoneSrvc.formatTzDate(moment(time), format);
}
private roundMinute(time: number) {
return this.timezoneSrvc.createTzDate(time).startOf('minute');
}
private roundSecond(time: number) {
return this.timezoneSrvc.createTzDate(time).startOf('second');
}
private roundYear(time: number) {
return this.timezoneSrvc.createTzDate(time).startOf('year');
}
private roundMonth(time: number) {
return this.timezoneSrvc.createTzDate(time).startOf('month');
}
private roundWeek(time: number) {
return this.timezoneSrvc.createTzDate(time).startOf('week');
}
private roundHour(time: number) {
return this.timezoneSrvc.createTzDate(time).startOf('hour');
}
private roundDay(time: number) {
return this.timezoneSrvc.createTzDate(time).startOf('day');
}
}