用于时间跟踪的MongoDB架构devise

我创build了一个简单的时间跟踪应用程序,在这个应用程序中,人们可以使用TimeIn, 此跟踪的中心对象是用户生成的事件 。 这与UserStatus结合确保了状态pipe理是正确的。 这里是schemas减去updatedAt createdAt字段:

{ 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 } } 

现在我正在尝试创build一个天事件的聚合。 在我脑海中的领域是totalWorkTime,totalBreakTime(以秒为单位),noOfBreaks,但我想解决的情况是当用户忘记超时。 请考虑:

  • 用户远在美国和马尼拉。
  • 用户没有任何时间段分配给他们。
  • 所以也许他们可以在当地时间从晚上11点到凌晨3点工作。
  • 如何区分上述情况从缺失超时,并适合当地的时区。
  • 存储本地时间是否聪明? 反对存储UTC。

主要想法是在第二天下午11:59和中午12:00超时。 但它适合很好。 Schema或者build议模式的任何帮助都是有帮助的。 谢谢!

以UTC和他们的时区偏移量存储时间。

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