11import React , { Component , Fragment } from 'react' ;
2- import moment from 'moment' ;
32
43import { WithTheme , withTheme } from '@material-ui/core/styles' ;
54import { Avatar , Divider , List , ListItem , ListItemAvatar , ListItemText , Button } from '@material-ui/core' ;
@@ -14,7 +13,7 @@ import RefreshIcon from '@material-ui/icons/Refresh';
1413
1514import { RestFormProps , FormButton , HighlightAvatar } from '../components' ;
1615import { isNtpActive , ntpStatusHighlight , ntpStatus } from './NTPStatus' ;
17- import { formatIsoDateTime , formatLocalDateTime } from './TimeFormat' ;
16+ import { formatDuration , formatDateTime , formatLocalDateTime } from './TimeFormat' ;
1817import { NTPStatus , Time } from './types' ;
1918import { redirectingAuthorizedFetch , withAuthenticatedContext , AuthenticatedContextProps } from '../authentication' ;
2019import { TIME_ENDPOINT } from '../api' ;
@@ -39,34 +38,34 @@ class NTPStatusForm extends Component<NTPStatusFormProps, NTPStatusFormState> {
3938 }
4039
4140 updateLocalTime = ( event : React . ChangeEvent < HTMLInputElement > ) => {
42- this . setState ( { localTime : event . target . value } ) ;
41+ this . setState ( {
42+ localTime : event . target . value
43+ } ) ;
4344 }
4445
4546 openSetTime = ( ) => {
46- this . setState ( { localTime : formatLocalDateTime ( moment ( ) ) , settingTime : true , } ) ;
47+ this . setState ( {
48+ localTime : formatLocalDateTime ( new Date ( ) ) ,
49+ settingTime : true
50+ } ) ;
4751 }
4852
4953 closeSetTime = ( ) => {
50- this . setState ( { settingTime : false } ) ;
54+ this . setState ( {
55+ settingTime : false
56+ } ) ;
5157 }
5258
53- 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 ( ) ;
59- return {
60- time_utc : newLocalTime . format ( )
61- }
62- }
59+ createTime = ( ) : Time => ( {
60+ local_time : formatLocalDateTime ( new Date ( this . state . localTime ) )
61+ } ) ;
6362
6463 configureTime = ( ) => {
6564 this . setState ( { processing : true } ) ;
6665 redirectingAuthorizedFetch ( TIME_ENDPOINT ,
6766 {
6867 method : 'POST' ,
69- body : JSON . stringify ( this . createAdjustedTime ( ) ) ,
68+ body : JSON . stringify ( this . createTime ( ) ) ,
7069 headers : {
7170 'Content-Type' : 'application/json'
7271 }
@@ -153,7 +152,7 @@ class NTPStatusForm extends Component<NTPStatusFormProps, NTPStatusFormState> {
153152 < AccessTimeIcon />
154153 </ Avatar >
155154 </ ListItemAvatar >
156- < ListItemText primary = "Local Time" secondary = { formatIsoDateTime ( data . time_local ) } />
155+ < ListItemText primary = "Local Time" secondary = { formatDateTime ( data . local_time ) } />
157156 </ ListItem >
158157 < Divider variant = "inset" component = "li" />
159158 < ListItem >
@@ -162,7 +161,7 @@ class NTPStatusForm extends Component<NTPStatusFormProps, NTPStatusFormState> {
162161 < SwapVerticalCircleIcon />
163162 </ Avatar >
164163 </ ListItemAvatar >
165- < ListItemText primary = "UTC Time" secondary = { formatIsoDateTime ( data . time_utc ) } />
164+ < ListItemText primary = "UTC Time" secondary = { formatDateTime ( data . utc_time ) } />
166165 </ ListItem >
167166 < Divider variant = "inset" component = "li" />
168167 < ListItem >
@@ -171,7 +170,7 @@ class NTPStatusForm extends Component<NTPStatusFormProps, NTPStatusFormState> {
171170 < AvTimerIcon />
172171 </ Avatar >
173172 </ ListItemAvatar >
174- < ListItemText primary = "Uptime" secondary = { moment . duration ( data . uptime , 'seconds' ) . humanize ( ) } />
173+ < ListItemText primary = "Uptime" secondary = { formatDuration ( data . uptime ) } />
175174 </ ListItem >
176175 < Divider variant = "inset" component = "li" />
177176 </ List >
0 commit comments