11import React , { Component , Fragment } from 'react' ;
2- import moment from 'moment ' ;
2+ import { DateTime } from 'luxon ' ;
33
44import { WithTheme , withTheme } from '@material-ui/core/styles' ;
55import { Avatar , Divider , List , ListItem , ListItemAvatar , ListItemText , Button } from '@material-ui/core' ;
@@ -14,7 +14,7 @@ import RefreshIcon from '@material-ui/icons/Refresh';
1414
1515import { RestFormProps , FormButton , HighlightAvatar } from '../components' ;
1616import { isNtpActive , ntpStatusHighlight , ntpStatus } from './NTPStatus' ;
17- import { formatIsoDateTime , formatLocalDateTime } from './TimeFormat' ;
17+ import { formatDuration , formatIsoDateTime , formatLocalDateTime , fromISOWithOffset , toISOWithOffset } from './TimeFormat' ;
1818import { NTPStatus , Time } from './types' ;
1919import { redirectingAuthorizedFetch , withAuthenticatedContext , AuthenticatedContextProps } from '../authentication' ;
2020import { TIME_ENDPOINT } from '../api' ;
@@ -43,21 +43,18 @@ class NTPStatusForm extends Component<NTPStatusFormProps, NTPStatusFormState> {
4343 }
4444
4545 openSetTime = ( ) => {
46- this . setState ( { localTime : formatLocalDateTime ( moment ( ) ) , settingTime : true , } ) ;
46+ this . setState ( { localTime : formatLocalDateTime ( DateTime . local ( ) ) , settingTime : true , } ) ;
4747 }
4848
4949 closeSetTime = ( ) => {
5050 this . setState ( { settingTime : false } ) ;
5151 }
5252
5353 createAdjustedTime = ( ) : Time => {
54- const currentLocalTime = moment ( this . props . data . time_local ) ;
55- const newLocalTime = moment ( this . state . localTime ) ;
56- newLocalTime . subtract ( currentLocalTime . utcOffset ( ) )
57- newLocalTime . milliseconds ( 0 ) ;
58- newLocalTime . utc ( ) ;
54+ const currentLocalTime = fromISOWithOffset ( this . props . data . time_local ) ;
55+ const newLocalTime = fromISOWithOffset ( this . state . localTime ) . minus ( currentLocalTime . offset ) . toUTC ( ) ;
5956 return {
60- time_utc : newLocalTime . format ( )
57+ time_utc : toISOWithOffset ( newLocalTime )
6158 }
6259 }
6360
@@ -171,7 +168,7 @@ class NTPStatusForm extends Component<NTPStatusFormProps, NTPStatusFormState> {
171168 < AvTimerIcon />
172169 </ Avatar >
173170 </ ListItemAvatar >
174- < ListItemText primary = "Uptime" secondary = { moment . duration ( data . uptime , 'seconds' ) . humanize ( ) } />
171+ < ListItemText primary = "Uptime" secondary = { formatDuration ( data . uptime ) } />
175172 </ ListItem >
176173 < Divider variant = "inset" component = "li" />
177174 </ List >
0 commit comments