MongoDB Schema Scheme for Time Tracking

I created a simple time tracking program in which people can use TimeIn, TimeOut and mark breaks. The central object of this tracking is the Event generated by the User . This, combined with UserStatus, ensures that the state is properly managed. Here are the schemes minus updateAt createdAt fields:

{
  userId: { type   : mongoose.Schema.Types.ObjectId, required: true },
  localTime:  {type: Date},
  userEmail: { type: String, required: true },
  type: { type   : String, required: true },
  ip: { type   : String, required: false }
}

Now I'm trying to create an event aggregation of days. The fields in my mind are totalWorkTime, totalBreakTime (in seconds), noOfBreaks, but the case I'm trying to solve is when users forget the timeout. Please consider:

  • Users are far away in the USA as well as in Manila.
  • Users do not have a time period assigned to them.
  • So, maybe they can work from 11pm to 3am local time.
  • How to distinguish the above situation from the lack of a timeout, and it goes well with local time zones.
  • Does local time keep smart? Against storing UTC.

Primary thinking was a timeout at 23:59 and at 12:00 AM the next day. But this dosage fits well. Any help with the Scheme or perhaps the proposed scheme should be helpful. Thanks!

+2
source share
1 answer

Save time in UTC and their time zone offset.

const now = new Date();
console.log( now.getTime() );
console.log( now.getTimezoneOffset() );
0
source

Source: https://habr.com/ru/post/1703287/


All Articles