fix(whereIts): return titlecased timezone names
This commit is contained in:
1 parent
fb5ecec15c
commit
081c965030
4 files changed
+30
-19
No files matched your search
+1
-18
@@ -2,6 +2,7 @@
|
||||
import findTz from './find.js'
|
||||
import inSummerTime from './summerTime.js'
|
||||
import getDstShift from './dstShift.js'
|
||||
import titleCase from './titleCase.js'
|
||||
|
||||
const parseDst = dst => {
|
||||
if (!dst) {
|
||||
@@ -10,24 +11,6 @@ const parseDst = dst => {
|
||||
return dst.split('->')
|
||||
}
|
||||
|
||||
//iana codes are case-sensitive, technically
|
||||
const titleCase = str => {
|
||||
str = str[0].toUpperCase() + str.substr(1)
|
||||
str = str.replace(/[/_-]([a-z])/gi, s => {
|
||||
return s.toUpperCase()
|
||||
})
|
||||
str = str.replace(/_(of|es)_/i, (s) => s.toLowerCase())
|
||||
str = str.replace(/\/gmt/i, '/GMT')
|
||||
str = str.replace(/\/utc/i, '/UTC')
|
||||
str = str.replace(/\/Dumontdurville$/i, '/DumontDUrville')
|
||||
str = str.replace(/\/Mcmurdo$/i, '/McMurdo')
|
||||
str = str.replace(/\/Port-au-prince$/i, '/Port-au-Prince')
|
||||
if (str === 'Utc') {
|
||||
str = 'UTC'
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
//get metadata about this timezone
|
||||
const timezone = s => {
|
||||
const zones = s.timezones
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//iana codes are case-sensitive, technically
|
||||
const titleCase = str => {
|
||||
str = str[0].toUpperCase() + str.substr(1)
|
||||
str = str.replace(/[/_-]([a-z])/gi, s => {
|
||||
return s.toUpperCase()
|
||||
})
|
||||
str = str.replace(/_(of|es)_/i, (s) => s.toLowerCase())
|
||||
str = str.replace(/\/gmt/i, '/GMT')
|
||||
str = str.replace(/\/utc/i, '/UTC')
|
||||
str = str.replace(/\/Dumontdurville$/i, '/DumontDUrville')
|
||||
str = str.replace(/\/Mcmurdo$/i, '/McMurdo')
|
||||
str = str.replace(/\/Port-au-prince$/i, '/Port-au-Prince')
|
||||
if (str === 'Utc') {
|
||||
str = 'UTC'
|
||||
}
|
||||
return str
|
||||
}
|
||||
export default titleCase
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
import Spacetime from './spacetime.js'
|
||||
import titleCase from './timezone/titleCase.js'
|
||||
// const timezones = require('../data');
|
||||
|
||||
const whereIts = (a, b) => {
|
||||
@@ -33,6 +34,6 @@ const whereIts = (a, b) => {
|
||||
}
|
||||
return false
|
||||
})
|
||||
return tzs
|
||||
return tzs.map(titleCase)
|
||||
}
|
||||
export default whereIts
|
||||
@@ -23,3 +23,12 @@ test('titlecase', (t) => {
|
||||
})
|
||||
t.end()
|
||||
})
|
||||
|
||||
test('whereIts returns titlecased names', (t) => {
|
||||
const tzs = spacetime.whereIts('12:00am', '11:59pm')
|
||||
t.ok(tzs.includes('Antarctica/Mawson'), 'Antarctica/Mawson')
|
||||
t.ok(tzs.includes('America/Port-au-Prince'), 'America/Port-au-Prince')
|
||||
const wrong = tzs.filter(tz => tz !== spacetime.now(tz).timezone().name)
|
||||
t.deepEqual(wrong, [], 'same name as timezone()')
|
||||
t.end()
|
||||
})
|
||||
Reference in new issue
Block a user