Skip to content

Commit 76da9e8

Browse files
authored
Merge pull request #9 from AndrewSouthpaw/patch-1
Fix overriding Intl in docs on Rails usage.
2 parents e1d0781 + ed736f3 commit 76da9e8

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

README.md

+9-14
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,16 @@ Further complicating matters, `jstz` uses the forward-thinking `window.Intl`, wh
8888

8989
```js
9090
export function findTimeZone() {
91-
// Because Intl is considered read-only and enforced on Android Chrome, we use Object.defineProperty to get around
9291
const oldIntl = window.Intl
93-
Object.defineProperty(window, 'Intl', {
94-
get() {},
95-
})
96-
97-
// get the timezone...
98-
const tz = jstz.determine().name()
99-
100-
// return Intl to original functionality
101-
Object.defineProperty(window, 'Intl', {
102-
get() { return oldIntl },
103-
})
104-
105-
return tz
92+
try {
93+
window.Intl = undefined
94+
const tz = jstz.determine().name()
95+
window.Intl = oldIntl
96+
return tz
97+
} catch (e) {
98+
// sometimes (on android) you can't override intl
99+
return jstz.determine().name()
100+
}
106101
}
107102
```
108103

0 commit comments

Comments
 (0)