11import { observer } from 'mobx-react' ;
22import React , { useEffect } from 'react' ;
33import { debounce } from 'lodash' ;
4- import dayjs , { Dayjs } from 'dayjs' ;
54import {
65 Button ,
76 DatePicker ,
@@ -10,6 +9,8 @@ import {
109 Input ,
1110 InputRef ,
1211 Space ,
12+ Switch ,
13+ Tooltip ,
1314} from 'antd' ;
1415import { SleuthState } from '../state/sleuth' ;
1516import {
@@ -25,6 +26,8 @@ import {
2526 SearchOutlined ,
2627 WarningOutlined ,
2728} from '@ant-design/icons' ;
29+ import { TZDate , tzOffset } from '@date-fns/tz' ;
30+ import dateFnsGenerateConfig from 'rc-picker/lib/generate/dateFns' ;
2831
2932export interface FilterProps {
3033 state : SleuthState ;
@@ -79,7 +82,7 @@ export const Filter = observer((props: FilterProps) => {
7982 } , 500 ) ;
8083
8184 const handleDateRangeChange = (
82- values : [ Dayjs , Dayjs ] ,
85+ values : [ TZDate , TZDate ] ,
8386 dateStrings : [ string , string ] ,
8487 ) => {
8588 props . state . dateRange = {
@@ -108,7 +111,9 @@ export const Filter = observer((props: FilterProps) => {
108111 />
109112 ) ;
110113
111- const { RangePicker } = DatePicker ;
114+ const { RangePicker } = DatePicker . generatePicker < Date > (
115+ dateFnsGenerateConfig ,
116+ ) ;
112117
113118 function renderFilter ( ) {
114119 const { error, warn, info, debug } = props . state . levelFilter ;
@@ -200,7 +205,6 @@ export const Filter = observer((props: FilterProps) => {
200205 key : 'reset' ,
201206 } ,
202207 ] ,
203- // onMouseLeave: (): void => setOpen(false),
204208 } }
205209 >
206210 < Button
@@ -210,17 +214,50 @@ export const Filter = observer((props: FilterProps) => {
210214 </ Dropdown >
211215 ) ;
212216 }
217+
218+ const systemTZ = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
219+ const userTZ = props . state . stateFiles [ 'log-context.json' ] ?. data ?. systemTZ ;
220+ const tz = props . state . isUserTZ ? userTZ : systemTZ ;
221+ const offset = tzOffset ( tz , new Date ( '2020-01-15T00:00:00Z' ) ) ;
222+ const isTZSwitchable = userTZ && userTZ !== systemTZ ;
223+
213224 return (
214225 < Space className = "SearchGroup" >
226+ { ! ! userTZ && (
227+ < div >
228+ < Space >
229+ < Tooltip
230+ placement = "right"
231+ title = { `${ tz } (UTC${ offset < 0 ? '' : '+' } ${ offset / 60 } )` }
232+ >
233+ < Switch
234+ disabled = { ! isTZSwitchable }
235+ checkedChildren = {
236+ isTZSwitchable
237+ ? 'TZ: System'
238+ : `TZ: UTC${ offset < 0 ? '' : '+' } ${ offset / 60 } `
239+ }
240+ unCheckedChildren = { 'TZ: User' }
241+ checked = { ! props . state . isUserTZ }
242+ onChange = { ( ) => {
243+ props . state . toggleTZ ( ) ;
244+ } }
245+ />
246+ </ Tooltip >
247+ </ Space >
248+ </ div >
249+ ) }
215250 < RangePicker
216- showTime = { {
217- defaultValue : [
218- dayjs ( '00:00:00' , 'HH:mm:ss' ) ,
219- dayjs ( '23:59:59' , 'HH:mm:ss' ) ,
220- ] ,
221- } }
251+ showTime
222252 onChange = { handleDateRangeChange }
223- allowEmpty = { [ true , true ] }
253+ value = { [
254+ props . state . dateRange . from
255+ ? new TZDate ( props . state . dateRange . from , tz )
256+ : null ,
257+ props . state . dateRange . to
258+ ? new TZDate ( props . state . dateRange . to , tz )
259+ : null ,
260+ ] }
224261 />
225262 < Divider type = "vertical" />
226263 < Space className = "FilterGroup" >
0 commit comments