1
1
import React , { Component , Fragment } from 'react' ;
2
- import moment from 'moment' ;
3
2
4
3
import { WithTheme , withTheme } from '@material-ui/core/styles' ;
5
4
import { Avatar , Divider , List , ListItem , ListItemAvatar , ListItemText , Button } from '@material-ui/core' ;
@@ -14,7 +13,7 @@ import RefreshIcon from '@material-ui/icons/Refresh';
14
13
15
14
import { RestFormProps , FormButton , HighlightAvatar } from '../components' ;
16
15
import { isNtpActive , ntpStatusHighlight , ntpStatus } from './NTPStatus' ;
17
- import { formatIsoDateTime , formatLocalDateTime } from './TimeFormat' ;
16
+ import { formatDuration , formatDateTime , formatLocalDateTime } from './TimeFormat' ;
18
17
import { NTPStatus , Time } from './types' ;
19
18
import { redirectingAuthorizedFetch , withAuthenticatedContext , AuthenticatedContextProps } from '../authentication' ;
20
19
import { TIME_ENDPOINT } from '../api' ;
@@ -39,34 +38,34 @@ class NTPStatusForm extends Component<NTPStatusFormProps, NTPStatusFormState> {
39
38
}
40
39
41
40
updateLocalTime = ( event : React . ChangeEvent < HTMLInputElement > ) => {
42
- this . setState ( { localTime : event . target . value } ) ;
41
+ this . setState ( {
42
+ localTime : event . target . value
43
+ } ) ;
43
44
}
44
45
45
46
openSetTime = ( ) => {
46
- this . setState ( { localTime : formatLocalDateTime ( moment ( ) ) , settingTime : true , } ) ;
47
+ this . setState ( {
48
+ localTime : formatLocalDateTime ( new Date ( ) ) ,
49
+ settingTime : true
50
+ } ) ;
47
51
}
48
52
49
53
closeSetTime = ( ) => {
50
- this . setState ( { settingTime : false } ) ;
54
+ this . setState ( {
55
+ settingTime : false
56
+ } ) ;
51
57
}
52
58
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
+ } ) ;
63
62
64
63
configureTime = ( ) => {
65
64
this . setState ( { processing : true } ) ;
66
65
redirectingAuthorizedFetch ( TIME_ENDPOINT ,
67
66
{
68
67
method : 'POST' ,
69
- body : JSON . stringify ( this . createAdjustedTime ( ) ) ,
68
+ body : JSON . stringify ( this . createTime ( ) ) ,
70
69
headers : {
71
70
'Content-Type' : 'application/json'
72
71
}
@@ -153,7 +152,7 @@ class NTPStatusForm extends Component<NTPStatusFormProps, NTPStatusFormState> {
153
152
< AccessTimeIcon />
154
153
</ Avatar >
155
154
</ ListItemAvatar >
156
- < ListItemText primary = "Local Time" secondary = { formatIsoDateTime ( data . time_local ) } />
155
+ < ListItemText primary = "Local Time" secondary = { formatDateTime ( data . local_time ) } />
157
156
</ ListItem >
158
157
< Divider variant = "inset" component = "li" />
159
158
< ListItem >
@@ -162,7 +161,7 @@ class NTPStatusForm extends Component<NTPStatusFormProps, NTPStatusFormState> {
162
161
< SwapVerticalCircleIcon />
163
162
</ Avatar >
164
163
</ ListItemAvatar >
165
- < ListItemText primary = "UTC Time" secondary = { formatIsoDateTime ( data . time_utc ) } />
164
+ < ListItemText primary = "UTC Time" secondary = { formatDateTime ( data . utc_time ) } />
166
165
</ ListItem >
167
166
< Divider variant = "inset" component = "li" />
168
167
< ListItem >
@@ -171,7 +170,7 @@ class NTPStatusForm extends Component<NTPStatusFormProps, NTPStatusFormState> {
171
170
< AvTimerIcon />
172
171
</ Avatar >
173
172
</ ListItemAvatar >
174
- < ListItemText primary = "Uptime" secondary = { moment . duration ( data . uptime , 'seconds' ) . humanize ( ) } />
173
+ < ListItemText primary = "Uptime" secondary = { formatDuration ( data . uptime ) } />
175
174
</ ListItem >
176
175
< Divider variant = "inset" component = "li" />
177
176
</ List >
0 commit comments