Skip to content

Commit

Permalink
Use Intl.DateTimeFormat() to set timezone cookie (#1794)
Browse files Browse the repository at this point in the history
* Use  Intl.DateTimeFormat() to set timezone cookie

* Fix timezone cookie check
  • Loading branch information
vidya-ram authored and miteshashar committed Jul 14, 2023
1 parent 2bd4fe0 commit 3f9033d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 2 additions & 7 deletions funnel/assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'jquery-modal';
import 'trunk8';
import jstz from 'jstz';
import 'jquery.cookie';
import Utils from './utils/helper';
import WebShare from './utils/webshare';
import ScrollHelper from './utils/scrollhelper';
Expand All @@ -14,6 +12,7 @@ import updateParsleyConfig from './utils/update_parsley_config';
import ReadStatus from './utils/read_status';
import LazyLoadMenu from './utils/lazyloadmenu';
import './utils/getDevicePixelRatio';
import setTimezoneCookie from './utils/timezone';
import 'muicss/dist/js/mui';

const pace = require('pace-js');
Expand Down Expand Up @@ -63,11 +62,7 @@ $(() => {
document.head.appendChild(polyfill);
}

// Detect timezone for login
if (!$.cookie('timezone')) {
$.cookie('timezone', jstz.determine().name(), { path: '/' });
}

setTimezoneCookie();
updateParsleyConfig();
});

Expand Down
15 changes: 15 additions & 0 deletions funnel/assets/js/utils/timezone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'jquery.cookie';

// Detect timezone for login
async function setTimezoneCookie() {
if (!$.cookie('timezone')) {
let timezone = Intl.DateTimeFormat()?.resolvedOptions()?.timeZone;
if (!timezone) {
const { default: jstz } = await import('jstz');
timezone = jstz.determine().name();
}
$.cookie('timezone', timezone, { path: '/' });
}
}

export default setTimezoneCookie;

0 comments on commit 3f9033d

Please sign in to comment.