creepjs
creepjs copied to clipboard
expand timezone fingerprint
- [x] digest/test
concept https://jsfiddle.net/s5pdt37r/3/
const getLocale = () => {
const constructors = [
'Collator',
'DateTimeFormat',
'DisplayNames',
'ListFormat',
'NumberFormat',
'PluralRules',
'RelativeTimeFormat',
]
const lang = {}
constructors.forEach(name => {
const { locale } = new Intl[name]().resolvedOptions()
lang[name] = locale
})
return lang
}
console.log(getLocale())
const getRelativeTime = () => {
const { locale } = new Intl.RelativeTimeFormat().resolvedOptions()
const relativeTime = new Intl.RelativeTimeFormat('locale', {
localeMatcher: 'best fit',
numeric: 'auto',
style: 'long'
})
return {
['1 second ago']: relativeTime.format(-1, 'second'),
['now']: relativeTime.format(0, 'second'),
['in 1 second']: relativeTime.format(1, 'second'),
['1 minute ago']: relativeTime.format(-1, 'minute'),
['this minute']: relativeTime.format(0, 'minute'),
['in 1 minute']: relativeTime.format(1, 'minute'),
['1 hour ago']: relativeTime.format(-1, 'hour'),
['this hour']: relativeTime.format(0, 'hour'),
['in 1 hour']: relativeTime.format(1, 'hour'),
['yesterday']: relativeTime.format(-1, 'day'),
['today']: relativeTime.format(0, 'day'),
['tomorrow']: relativeTime.format(1, 'day'),
['last week']: relativeTime.format(-1, 'week'),
['this week']: relativeTime.format(0, 'week'),
['next week']: relativeTime.format(1, 'week'),
['last month']: relativeTime.format(-1, 'month'),
['this month']: relativeTime.format(0, 'month'),
['next month']: relativeTime.format(1, 'month'),
['last quarter']: relativeTime.format(-1, 'quarter'),
['this quarter']: relativeTime.format(0, 'quarter'),
['next quarter']: relativeTime.format(1, 'quarter'),
['last year']: relativeTime.format(-1, 'year'),
['this year']: relativeTime.format(0, 'year'),
['next year']: relativeTime.format(1, 'year')
}
}
console.log(getRelativeTime())
concept inspired by https://github.com/ghacksuserjs/TorZillaPrint
const confirmTimezone = timezone => {
let lie = false
const minute = 60000
const winter = new Date('1/1/1984')
const spring = new Date('4/1/1984')
const summer = new Date('7/1/1984')
const fall = new Date('10/1/1984')
const winterUTCTime = +new Date('1984-01-01')
const springUTCTime = +new Date('1984-04-01')
const summerUTCTime = +new Date('1984-07-01')
const fallUTCTime = +new Date('1984-10-01')
const date = {
winter: {
time: (+winter - winterUTCTime)/minute,
parse: (Date.parse(winter) - winterUTCTime)/minute
},
spring: {
time: (+spring - springUTCTime)/minute,
parse: (Date.parse(spring) - springUTCTime)/minute
},
summer: {
time: (+summer - summerUTCTime)/minute,
parse: (Date.parse(summer) - summerUTCTime)/minute
},
fall: {
time: (+fall - fallUTCTime)/minute,
parse: (Date.parse(fall) - fallUTCTime)/minute
}
}
lie = !!Object.keys(date).filter(key => {
const season = date[key]
return season.time != season.parse
}).length
lie = !new Set(
[].concat(
...Object.keys(date).map(key => {
const season = date[key]
return [season.time, season.parse]
})
)
).has(timezone)
return { ...date, lie }
}
const timezone = new Date().getTimezoneOffset()
console.log(confirmTimezone(timezone))
console.log(getLocale()) -> type error
@Thorin-Oakenpants
LOL, 1984 is an interesting year. "Time After Time" by Cyndi Lauper became a major hit that year.
console.log(getLocale()) -> type error
Hmmm... I'm not seeing this in FF nightly. I'll refactor a bit and see what I can find.

Uncaught TypeError: Intl[name] is not a constructor
it's display names that causes a problem (on nightly)
try {
const { locale } = new Intl[name]().resolvedOptions()
lang[name] = locale
} catch(e) {
console.debug(name, e.name, e.message)
}
DisplayNames is missing
{…}
Collator: "en-US"
DateTimeFormat: "en-US"
ListFormat: "en-US"
NumberFormat: "en-US"
PluralRules: "en-US"
RelativeTimeFormat: "en-US"
Should be fixed in 14a08d6. I threw new Intl[name]) in a try catch function. But, let me know if it persists.
I'm going to nab this and expand my languages section on TZP
current
..nav props...
[DateTimeFormat] locale | en-US
[Intl.PluralRules] locale | en-US
[Intl.ListFormat] locale | en-US
I do have DisplayNames on my ToDo (obviously not landed in FF yet), and I do have extra stuff here ToDo with Collator, and I guess I check the other ones in the formatting section, but it'd be nice to add the missing ones in this section
Go for it. Always welcome.
I'm commenting out DisplayNames for now. It throws an error in Chrome canary too.
don't forget 1423593 😁 .... PS: here's DisplayNames