Add locale for expiry date

This commit is contained in:
Alan Grainger
2026-07-17 14:58:33 +12:00
parent c1e2d3c0e7
commit ca5d23c6d7
5 changed files with 60 additions and 10 deletions
+17
View File
@@ -1,5 +1,6 @@
import { describe, it, expect, beforeEach } from 'vitest'
import dayjs from 'dayjs'
import 'dayjs/locale/de' // load German so the localised-format assertions are deterministic
import { expiryDate } from '../src/share'
import { loadConfig } from '../src/config/loader'
import { KeyType, SharedLink } from '../src/types'
@@ -58,4 +59,20 @@ describe('expiryDate', () => {
setConfig({ ipp: { gallery: { showExpiryDate: true } } })
expect(expiryDate(share('not-a-date'))).toBeUndefined()
})
it('localises name tokens with a configured expiryDateLocale', () => {
setConfig({ ipp: { gallery: { showExpiryDate: true, expiryDateFormat: 'D MMMM YYYY', expiryDateLocale: 'de' } } })
// "10 Juli 2026" in German, not "10 July 2026"
expect(expiryDate(share(EXPIRES))).toBe(dayjs(EXPIRES).locale('de').format('D MMMM YYYY'))
})
it('accepts a locale case-insensitively', () => {
setConfig({ ipp: { gallery: { showExpiryDate: true, expiryDateFormat: 'D MMMM YYYY', expiryDateLocale: 'DE' } } })
expect(expiryDate(share(EXPIRES))).toBe(dayjs(EXPIRES).locale('de').format('D MMMM YYYY'))
})
it('falls back to English for an unknown or malformed locale', () => {
setConfig({ ipp: { gallery: { showExpiryDate: true, expiryDateFormat: 'D MMMM YYYY', expiryDateLocale: '../en' } } })
expect(expiryDate(share(EXPIRES))).toBe(dayjs(EXPIRES).locale('en').format('D MMMM YYYY'))
})
})