mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[timezones] Add comment explaining moment to Date conversion
This commit is contained in:
parent
f9ee4e3ab0
commit
4516b9e00e
1 changed files with 10 additions and 1 deletions
|
@ -3,6 +3,13 @@ define(function (require) {
|
|||
var angular = require('angular');
|
||||
var moment = require('moment');
|
||||
|
||||
/**
|
||||
* moment objects can have an associated timezone, and when converting to a Date the
|
||||
* timezone is changed to browser time. This can cause issues, such as a day picker
|
||||
* showing the wrong day.
|
||||
* When a moment date is passed in, offset the timezone so that after converting to a Date object
|
||||
* the day does not appear changed. When reading back, convert to moment and remove the offset.
|
||||
*/
|
||||
require('ui/modules')
|
||||
.get('kibana')
|
||||
.directive('offsetTimezone', function () {
|
||||
|
@ -18,6 +25,7 @@ define(function (require) {
|
|||
// continue to offset the date.
|
||||
var offsetDate = false;
|
||||
|
||||
//Going from Date object to moment
|
||||
function fromDatePicker(value) {
|
||||
if (!value) return;
|
||||
var date = moment(value);
|
||||
|
@ -30,10 +38,11 @@ define(function (require) {
|
|||
return date;
|
||||
}
|
||||
|
||||
//Going from moment to Date object
|
||||
function toDatePicker(value) {
|
||||
if (!value) return;
|
||||
|
||||
var date = new Date(value.format('YYYY-MM-DDTHH:mm:ss.SSSZ'));
|
||||
|
||||
var offset = date.getTimezoneOffset() + value.utcOffset();
|
||||
date.setMinutes(date.getMinutes() + offset);
|
||||
offsetDate = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue