1111 */
1212
1313import async from "async" ;
14- import dayjs from "dayjs " ;
14+ import { DateTime } from "luxon " ;
1515
1616import { Analysis , Resources , Utils } from "@tago-io/sdk" ;
1717import { DeviceInfo , DeviceListItem , TagoContext } from "@tago-io/sdk/lib/types" ;
@@ -38,9 +38,9 @@ async function resolveOrg(org: DeviceListItem) {
3838 } ) ;
3939
4040 for ( const sensor of sensorList ) {
41- const last_input = dayjs ( sensor . last_input ) ;
42- const now = dayjs ( ) ;
43- const diff_time = now . diff ( last_input , "hours" ) ;
41+ const last_input = DateTime . fromISO ( String ( sensor . last_input || "" ) ) ;
42+ const now = DateTime . now ( ) ;
43+ const diff_time = now . diff ( last_input , "hours" ) . hours ;
4444 total_qty ++ ;
4545 if ( diff_time < 24 ) {
4646 active_qty ++ ;
@@ -136,15 +136,15 @@ async function resolveDevice(context: TagoContext, org_id: string, device_id: st
136136 return Promise . reject ( "Device not found" ) ;
137137 }
138138
139- const checkin_date = dayjs ( device_info . last_input ) ;
139+ const checkin_date = DateTime . fromISO ( device_info . last_input . toString ( ) ) ;
140140
141- if ( ! checkin_date ) {
141+ if ( ! checkin_date . isValid ) {
142142 return "no data" ;
143143 }
144144
145- let diff_hours : string | number = dayjs ( ) . diff ( checkin_date , "hours" ) ;
145+ let diff_hours : string | number = DateTime . now ( ) . diff ( checkin_date , "hours" ) . hours ;
146146
147- if ( diff_hours !== diff_hours ) {
147+ if ( isNaN ( diff_hours ) ) {
148148 diff_hours = "-" ;
149149 } //checking for NaN
150150
0 commit comments