import zoomPlugin from 'chartjs-plugin-zoom'
import { Observable, of } from 'rxjs'
import { SelectOptionsItem } from 'src/types'
-import { Component, OnInit } from '@angular/core'
+import { Component, Inject, LOCALE_ID, OnInit } from '@angular/core'
import { ActivatedRoute } from '@angular/router'
import { Notifier, PeerTubeRouterService } from '@app/core'
import { NumberFormatterPipe, VideoDetails } from '@app/shared/shared-main'
private chartIngestData: { [ id in ActiveGraphId ]?: ChartIngestData } = {}
constructor (
+ @Inject(LOCALE_ID) private localeId: string,
private route: ActivatedRoute,
private notifier: Notifier,
private statsService: VideoStatsService,
getViewersStatsTitle () {
if (this.statsStartDate && this.statsEndDate) {
- return $localize`Viewers stats between ${this.statsStartDate.toLocaleString()} and ${this.statsEndDate.toLocaleString()}`
+ return $localize`Viewers stats between ${this.toMediumDate(this.statsStartDate)} and ${this.toMediumDate(this.statsEndDate)}`
}
return $localize`Viewers stats`
private buildLiveFilter (session: LiveVideoSession) {
return {
id: session.startDate + '|' + session.endDate,
- label: $localize`Live as of ${new Date(session.startDate).toLocaleString()}`
+ label: $localize`Live as of ${this.toMediumDate(new Date(session.startDate))}`
}
}
label: $localize`Peak viewers`,
value: this.numberFormatter.transform(overallStats.viewersPeak),
moreInfo: overallStats.viewersPeak !== 0
- ? $localize`at ${new Date(overallStats.viewersPeakDate).toLocaleString()}`
+ ? $localize`at ${this.toMediumDate(new Date(overallStats.viewersPeakDate))}`
: undefined
},
{
if (graphId === 'retention') return value + ' %'
if (graphId === 'aggregateWatchTime') return secondsToTime(+value)
- return value.toLocaleString()
+ return value.toLocaleString(this.localeId)
}
private formatTooltipTitle (options: {
const { graphId, items } = options
const item = items[0]
- if (this.isTimeserieGraph(graphId)) return new Date(item.label).toLocaleString()
+ if (this.isTimeserieGraph(graphId)) {
+ return this.toMediumDate(new Date(item.label))
+ }
return item.label
}
}
}
+ private toMediumDate (d: Date) {
+ return new Date(d).toLocaleString(this.localeId, {
+ day: 'numeric',
+ month: 'short',
+ year: 'numeric',
+ hour: 'numeric',
+ minute: 'numeric',
+ second: 'numeric'
+ })
+ }
+
private buildZoomEndDate (groupInterval: string, last: string) {
const date = new Date(last)