mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Fix locale-dependent tests. Closes #2402
This commit is contained in:
parent
7c92a73208
commit
36eda871f6
2 changed files with 6 additions and 13 deletions
|
@ -25,7 +25,7 @@ export const formatDuration = (d) => {
|
|||
return `${days > 0 ? days + ':' : ''}${f}`
|
||||
}
|
||||
|
||||
export const formatFullDate = (date) => {
|
||||
export const formatFullDate = (date, locale) => {
|
||||
const dashes = date.split('-').length - 1
|
||||
let options = {
|
||||
year: 'numeric',
|
||||
|
@ -36,5 +36,5 @@ export const formatFullDate = (date) => {
|
|||
if (dashes > 2 || (dashes === 0 && date.length > 4)) {
|
||||
return ''
|
||||
}
|
||||
return new Date(date).toLocaleDateString(undefined, options)
|
||||
return new Date(date).toLocaleDateString(locale, options)
|
||||
}
|
||||
|
|
|
@ -33,17 +33,10 @@ describe('formatDuration', () => {
|
|||
})
|
||||
|
||||
describe('formatFullDate', () => {
|
||||
beforeAll(() => {
|
||||
const toLocaleString = Date.prototype.toLocaleString
|
||||
// eslint-disable-next-line no-extend-native
|
||||
Date.prototype.toLocaleString = function (locale = 'en-US', ...args) {
|
||||
return toLocaleString.call(this, locale, ...args)
|
||||
}
|
||||
})
|
||||
it('format bytes', () => {
|
||||
expect(formatFullDate('2011')).toEqual('2011')
|
||||
expect(formatFullDate('2011-06')).toEqual('Jun 2011')
|
||||
expect(formatFullDate('1985-01-01')).toEqual('Jan 1, 1985')
|
||||
it('format dates', () => {
|
||||
expect(formatFullDate('2011', 'en-US')).toEqual('2011')
|
||||
expect(formatFullDate('2011-06', 'en-US')).toEqual('Jun 2011')
|
||||
expect(formatFullDate('1985-01-01', 'en-US')).toEqual('Jan 1, 1985')
|
||||
expect(formatFullDate('199704')).toEqual('')
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue