django使用ORM(PostgreSQL)覆盖的日期如何分开持续时间。

发布于 2025-02-09 13:26:04 字数 363 浏览 0 评论 0原文

使用Django(带有PostgreSQL),我有一个模型,该模型代表具有一定的起始时刻(start_dateTime)和持续时间的活动。

因此,一项活动可能覆盖了一天以上,我想知道连续日期(天)上它涵盖了多少时间。因此,一个例子是,所有使用UTC时区都将在2022-12-24T12:00开始48小时的约会,这将在20222-12-26T12:00上结束,每天给予持续时间:

  • 2022-12 -24-12小时
  • 2022-12-25-24小时
  • 2022-12-26-12小时

,我想获取此信息以进行一年的活动,以提供一个人的日历。

这是可能的吗?理想情况下,我还可以指定需要确定此数据的时区。

Using Django (with PostgreSQL) I have a model that represents activities with a certain starting moment (start_datetime) and a duration.

So it is possible that an activity covers more than one day, and I would like to know per activity how much time it covers on consecutive dates (days). So an example would be, all using UTC timezone, to have a 48 hour appointment start on 2022-12-24T12:00, which would have the activity end on 2022-12-26T12:00, giving duration per day:

  • 2022-12-24 - 12 hours
  • 2022-12-25 - 24 hours
  • 2022-12-26 - 12 hours

And I would like to get this information for up to a year's worth of activities, for a single person's calendar.

Is this possible, and if so does anyone have an example of how to achieve this? Ideally I would also be able to specify the timezone that this data needs to be determined in.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坠似风落 2025-02-16 13:26:04

您可以使用models.durationfield

you can use models.DurationField (https://www.geeksforgeeks.org/durationfield-django-models/) and specify any duration, also in the model you need to create a field from which moment to count and either indicate what the timezone is there or save it separately in the field for each record

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文