datetimepicker
datetimepicker copied to clipboard
Add a Timezone Offset
Now the actual timezone is calculated by the browsers timezone. I would appreciate if we could have some sort of timezone offset (something like highcharts has http://api.highcharts.com/highstock#global.timezoneOffset)
+1
+1
Hi, we're using this wonderful time picker at Friendica, and we ran into an issue where one of our users spoofed their browser clock to defeat fingerprinting and were presented with unexpected default time in the picker: https://github.com/friendica/friendica/issues/10691
Now since we do collect the timezone information from users, if this library had a timezoneOffset
option we could supply it on our end to not have to care about the browser-supplied timezone.
This is a challenge.
For Javascript, the timezone is defined by the browser.
new Date()
will return a valid date for the current time/date. However, the Timezone Offset will be defined by the browser.
Using the value:
parameter in this library and passing it a JS Date()
object presents the challenge -- it will show the formatted Date and Time in the user/browser Timezone, not the Timezone you might want to show it in.
The reason this is useful is if you want someone to select a date and time between say 8am and 8pm in a specific timezone, not within their own Timezone.
While the value:
parameter might be a Date()
object, it would be useful to pass a named Timezone such as America/New_York
and use the toLocaleString()
method to get the valid date/time for that Timezone from the Date()
object, then grab that and format it.
Maybe I'll do a pull request and see if I can implement.
Pseudocode:
var d = new Date()
$('#dpt').datetimepicker({format: 'M j, Y g:i A', value: d, timezone: "America/New_York"})
// behind the scenes in the library
// Output the LocaleString. Maybe this should be in a fixed Locale to make parsing deterministic
var str = value.toLocaleString('en-US', {timeZone:timezone})
// Parse the string parts into an object to make formatting easier
var newobj = parse_localeString(str)
// Set the value of the Text Input to the timezone-corrected Date/Time
this.val(output_the_value_using_the_defined_format(newobj, format))
This may need to require changes in the validation code, which I found buggy enough that I disabled it onblur.