用于时间跟踪的MongoDB模式设计 [英] MongoDB Schema Design for Time Tracking

查看:95
本文介绍了用于时间跟踪的MongoDB模式设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的时间跟踪应用程序,人们可以在其中进行TimeIn,TimeOut和中断标记.此跟踪的中心对象是由用户生成的事件.结合 UserStatus 可以确保状态管理正确.以下是减去 updatedAt createdAt 字段的架构:

I have created a simple time tracking application in which people can TimeIn, TimeOut and mark breaks. The central object to this Tracking is an Event generated by User. This combined with UserStatus makes sure the state management is correct. Here are the schemas minus updatedAt 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 }
}

现在,我正在尝试创建几天事件的汇总.我想到的字段是totalWorkTime,totalBreakTime(以秒为单位),noOfBreaks,但我要解决的情况是用户忘记超时时.请考虑:

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

  • 用户遍及美国和马尼拉.
  • 用户没有分配任何时间段.
  • 因此,也许他们可以在当地时间从晚上11点到凌晨3点工作.
  • 如何将上述情况与超时丢失区分开来,并与当地时区很好地吻合.
  • 存储本地时间是否很聪明?反对存储UTC.

主要思想是在第二天的11:59 PM和12:00 AM超时和超时.但是它非常适合.对模式或建议的模式的任何帮助都将有所帮助.谢谢!

Primary thinking was to timein and timeout at 11:59PM and 12:00AM the next day. But it dosent fit well. Any help with Schema or perhaps suggested schema shall be helpful. Thanks!

推荐答案

以UTC存储时间及其时区偏移量.

Store the times in UTC and their timezone offset.

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

这篇关于用于时间跟踪的MongoDB模式设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆