 
import { addHours, addMinutes, addSeconds, intervalToDuration, add } from "date-fns";   

 const sumOnlineTimeNow = (oldOnlineTimeSum:any) => {

          let onlineTime = new Date()

          onlineTime.setUTCHours(new Date(oldOnlineTimeSum.onlineTime).getHours())
          onlineTime.setUTCMinutes(new Date(oldOnlineTimeSum.onlineTime).getMinutes())
          onlineTime.setUTCSeconds(new Date(oldOnlineTimeSum.onlineTime).getSeconds())
 

          let newtTime = intervalToDuration({ start: new Date(oldOnlineTimeSum.updatedAt), end: new Date() })


          if (newtTime.hours && +newtTime.hours > 0) {
            onlineTime = addHours(onlineTime, newtTime.hours)
          }
          if (newtTime.minutes && +newtTime.minutes > 0) {
            onlineTime = addMinutes(onlineTime, newtTime.minutes)
          }
          if (newtTime.seconds && +newtTime.seconds > 0) {
            onlineTime = addSeconds(onlineTime, newtTime.seconds)
          }

          const isoDate = new Date(onlineTime);
          const newOnlinetime = isoDate.toJSON().slice(0, 19).replace('T', ' '); 

          return newOnlinetime
}

export default sumOnlineTimeNow