有天工作不夜在NodaTime启动 [英] Working with days which don't start at midnight in NodaTime

查看:145
本文介绍了有天工作不夜在NodaTime启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作有列车时刻表,其中第一个火车是0400,而末班车时间在0200这个应用程序的用户,因此应对启动0300天,在0300结束。换句话说,当一个应用程序他们说:周三的火车0200,他们真的是留下周四0200火车。

I am working on an application with train schedules, where the first train leaves at 0400 while the last train leaves at 0200. The users of this application therefore deal with days starting at 0300 and ending at 0300. In other words, when they say "The Wednesday-train at 0200" they really mean "The train that leaves on Thursday at 0200".

我们的应用程序需要存储所有列车离开上(例如)周三,这意味着它不应包含0300之前离开列车,但它应该包括火车那第二天离开的,直到0300

Our application needs to store all of the trains leaving on (for example) Wednesday, which means it should not include the trains that leave before 0300 but it should include the trains that leave the next day until 0300.

我将如何代表这在应用程序,而要疯了?而如何把这个存储在方便查询数据库?

How would I represent this in application without going mad? And how should this be stored in a database for easy querying?

推荐答案

我将存储的实际日期/时间值。然后进行查询,搜索什么周三你会从0400周三(含)到周四0400(不含)。

I would store the actual date/time value. Then for querying, to search for "anything on Wednesday" you'd go from Wednesday 0400 (inclusive) to Thursday 0400 (exclusive).

在显示方面,你倒是可能是最好服用日期,并减去一天,如果时间超过一定截止前面:

In terms of display, you'd probably be best taking the date, and subtracting a day if the time is earlier than some cutoff:

private static readonly LocalTime CutOff = new LocalTime(4, 0, 0);

...
LocalDate date = dateTime.Date;
if (dateTime.TimeOfDay < CutOff)
{
    date = date.PlusDays(-1);
}
var dayOfWeek = date.IsoDayOfWeek;



我会尽量避免使用它自己的日期尽量避免去疯了。任何日期/时间将是明确的。

I would try to avoid using the date on its own as far as possible, to avoid going mad. Any date/time will be unambiguous.

这篇关于有天工作不夜在NodaTime启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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