Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand timezone fingerprint #63

Open
1 task done
abrahamjuliot opened this issue Aug 15, 2020 · 9 comments
Open
1 task done

expand timezone fingerprint #63

abrahamjuliot opened this issue Aug 15, 2020 · 9 comments
Labels
enhancement New feature or request

Comments

@abrahamjuliot
Copy link
Owner

abrahamjuliot commented Aug 15, 2020


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())
@abrahamjuliot abrahamjuliot added the enhancement New feature or request label Aug 15, 2020
@abrahamjuliot
Copy link
Owner Author

abrahamjuliot commented Aug 20, 2020

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))

abrahamjuliot added a commit that referenced this issue Aug 20, 2020
@Thorin-Oakenpants
Copy link

console.log(getLocale()) -> type error

Repository owner deleted a comment from Thorin-Oakenpants Aug 20, 2020
@abrahamjuliot
Copy link
Owner Author

@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.

image

@Thorin-Oakenpants
Copy link

Uncaught TypeError: Intl[name] is not a constructor

@Thorin-Oakenpants
Copy link

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"

@abrahamjuliot
Copy link
Owner Author

Should be fixed in 14a08d6. I threw new Intl[name]) in a try catch function. But, let me know if it persists.

@Thorin-Oakenpants
Copy link

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

abrahamjuliot added a commit that referenced this issue Aug 20, 2020
@abrahamjuliot
Copy link
Owner Author

Go for it. Always welcome.

I'm commenting out DisplayNames for now. It throws an error in Chrome canary too.

abrahamjuliot added a commit that referenced this issue Aug 20, 2020
@Thorin-Oakenpants
Copy link

don't forget 1423593 😁 .... PS: here's DisplayNames

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants