@@ -32,6 +32,22 @@ import { timefilter } from '../../timefilter';
3232import dropPartialTemplate from '../controls/drop_partials.html' ;
3333import { i18n } from '@kbn/i18n' ;
3434
35+ function getCookie ( cname ) {
36+ const name = cname + '=' ;
37+ const decodedCookie = decodeURIComponent ( document . cookie ) ;
38+ const ca = decodedCookie . split ( ';' ) ;
39+ for ( let i = 0 ; i < ca . length ; i ++ ) {
40+ let c = ca [ i ] ;
41+ while ( c . charAt ( 0 ) === ' ' ) {
42+ c = c . substring ( 1 ) ;
43+ }
44+ if ( c . indexOf ( name ) === 0 ) {
45+ return c . substring ( name . length , c . length ) ;
46+ }
47+ }
48+ return '' ;
49+ }
50+
3551const config = chrome . getUiSettingsClient ( ) ;
3652const detectedTimezone = tzDetect . determine ( ) . name ( ) ;
3753const tzOffset = moment ( ) . format ( 'Z' ) ;
@@ -52,6 +68,7 @@ function setBounds(agg, force) {
5268}
5369
5470
71+
5572export const dateHistogramBucketAgg = new BucketAggType ( {
5673 name : 'date_histogram' ,
5774 title : i18n . translate ( 'common.ui.aggTypes.buckets.dateHistogramTitle' , {
@@ -157,9 +174,16 @@ export const dateHistogramBucketAgg = new BucketAggType({
157174 } ,
158175 {
159176 name : 'time_zone' ,
160- default : ( ) => {
161- const isDefaultTimezone = config . isDefault ( 'dateFormat:tz' ) ;
162- return isDefaultTimezone ? detectedTimezone || tzOffset : config . get ( 'dateFormat:tz' ) ;
177+ write : ( agg , output ) => {
178+ if ( config . isDefault ( 'dateFormat:tz' ) ) {
179+ output . params . time_zone = getCookie ( 'timezone' ) ;
180+ }
181+ else if ( config . get ( 'dateFormat:tz' ) === 'Browser' ) {
182+ output . params . time_zone = detectedTimezone || tzOffset ;
183+ }
184+ else {
185+ output . params . time_zone = config . get ( 'dateFormat:tz' ) ;
186+ }
163187 } ,
164188 } ,
165189 {
0 commit comments