一个月的第一周/最后一周是星期几?

发布于 2024-07-14 05:49:47 字数 715 浏览 4 评论 0原文

如果有人说某个月的第一周或最后一周发生了什么事,你会如何定义这个时间跨度?


背景

我正在开发一个需要以直观的方式处理此类事情的库,但我的直觉并不支持一种情况或另一种情况。

我可以让它选择不同的行为,但仍然需要一个好的默认值。


我将随机选择一个月份:2008 年 7 月

s  m  t  w  r  f  s
--------------------
      1  2  3  4  5
6  7  8  9  10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

(注意:我假设一周从星期日开始,但也可以在星期一提出问题)

举一个具体的例子, 该月的第一周?

  1. 6 月 29 日 - 7 月 5 日 -- 包括第一周
  2. 7 月 6 日 - 12 日 -- 该月的第一周

第二周只是第一次之后7天对吗?

该月的最后一周是多长时间?

  1. 7 月 27 日 - 8 月 2 日 -- 同上,但最后一天
  2. 7 月 20 - 26 日 -- 同上,但上周

欢迎非维基评论

If someone were to say something happens in the first or last week of some month, how would you define that span?


Background

I'm working on a library that needs to handle this kind of thing in an intuitive way, but my intuition doesn't claim one case or the other.

I can make it select different behavior but still need a good default.


For a concrete example I'll just to pick an random month: July 2008

s  m  t  w  r  f  s
--------------------
      1  2  3  4  5
6  7  8  9  10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

(Note: I'll assume the week starts with Sunday but the question could be asked re Monday as well)

What span is the first week of the month?

  1. June 29 - July 5 -- the week that includes the first
  2. July 6 - 12 -- the first week that is all the way into the month

The second week is just the 7 days following the first right?

What span is the last week of the month?

  1. July 27 - Aug 2 -- ditto but the last day
  2. July 20 - 26 -- ditto but the last week

Non wiki comments welcome

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

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

发布评论

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

评论(10

孤独患者 2024-07-21 05:49:47

没有答案,因为即使在一个国家内部情况也有所不同。

但是,< a href="http://www.perlmonks.org/?node_id=484347" rel="noreferrer">此来源似乎认为 ISO 标准将其定义为包含星期四的第一周。 然而,上述消息来源称,ISO 标准并未列出“每月第一周”的规范


超过 300 个字符 - 抱歉!

ISO 8601 标准将一年的第一周定义为:

日历周数

序号,根据第一个日历周的规则标识其日历年中的日历周
一年中的日历周是指包括该年的第一个星期四和最后一个日历的一周
日历年的周是紧接下一个日历年的第一个日历周之前的一周

ISO 8601 中没有关于该月的第一周的内容,因为如前所述,定义因国家/地区(甚至公司)而异。例如)。 哦,标准规定每周从星期一开始。

There is no answer because it varies even inside a country.

However, this source seems to think it's defined by the ISO standard as the first week that contains a thursday. However the above source says that the ISO standard does not list a specification for 'first week of the month'


More than 300 chars - sorry!

The ISO 8601 standard defines the first week of the YEAR as:

calendar week number

ordinal number which identifies a calendar week within its calendar year according to the rule that the first
calendar week of a year is that one which includes the first Thursday of that year and that the last calendar
week of a calendar year is the week immediately preceding the first calendar week of the next calendar year

There is nothing in ISO 8601 about the first week of the month because, as has been noted, the definition varies by country (and even by company, for example). Oh, and the standard says that weeks start on Monday.

心清如水 2024-07-21 05:49:47

如果您正在构建一个库,您应该允许用户选择他们想要如何处理它,方法是返回该月的第一周/最后一周的完整/部分周,或者传递一个参数来指示您是否想要完整/部分周。部分周。 如果您提供不需要规范的方法,请清楚地记录默认值。

public Week GetFirstFullWeekOfMonth( DateTime forDate ) { }

public Week GetFirstPartialWeekOfMonth( DateTime forDate ) { }

或者

public Week GetFirstWeekOfMonth( DateTime forDate, bool includePartial ) {}

If you are building a library, you should allow the user to choose how they want to handle it either by having methods that return the first/last full/partial week of the month or by passing an argument that indicates whether you want the full/partial week. Clearly document whichever is the default if you provide methods that don't require the specification.

public Week GetFirstFullWeekOfMonth( DateTime forDate ) { }

public Week GetFirstPartialWeekOfMonth( DateTime forDate ) { }

Or

public Week GetFirstWeekOfMonth( DateTime forDate, bool includePartial ) {}
金橙橙 2024-07-21 05:49:47

的一周

  1. 该月的第一周是包含第一个6 月 29 日至 7 月 5 日

The first week of the month is the week that includes the first

  1. June 29 - July 5
仅冇旳回忆 2024-07-21 05:49:47

间的第一周

  1. 该月的第一周是指7 月 6 日至 12 日期

The first week of the month is the first week that is all the way int the month

  1. July 6 - 12
倾`听者〃 2024-07-21 05:49:47

最后一天的那一周

  1. 该月的最后一周是包含7 月 27 日至 8 月 2 日

The last week of the month is the week that includes the last day

  1. July 27 - Aug 2
梦晓ヶ微光ヅ倾城 2024-07-21 05:49:47

日期间的最后一周

  1. 该月的最后一周是指7 月 20 日至 26

The last week of the month is the last week that is all the way int the month

  1. July 20 - 26
你不是我要的菜∠ 2024-07-21 05:49:47

该月的第一周是第 0 周 - 该周有该月的第一天。
最后一周是该月最后一天的一周,

因此 7 月最后一周的周数与 8 月第一周的周数相同

** 除非 **

该月份在该月的最后一天结束上周,在这种情况下,下个月将从新一周的第一天开始,并有不同的周数

:)

The first week of the month is week 0 - the week that has the first day of the month.
The last week is the week with the last day of the month

Hence the weeknumber of the last week of july IS THE SAME as the weeknumber of the first week of august

** UNLESS **

the month in question ends on the last day of the last week, in wich case the following month would start on the first day of the new week and have a different weeknumber

:)

-小熊_ 2024-07-21 05:49:47

我的定义是第一周是该月第一个工作日的那一周,
同样,最后一周是该月最后一个工作日的那一周。

My definition would be the first week is the week of the first working day in the month,
and likewise the last week is the week of the last working day in the month.

埋葬我深情 2024-07-21 05:49:47

该月的第一周是指拥有 4 天或更多天的定义周期间的第一周。 (不是真的,但我想我会把它作为一个选项)

The first week of the month is the first week that owns 4 or more days of the defined week period. (Not really but I thought I'd throw it in as an option)

海拔太高太耀眼 2024-07-21 05:49:47

您缺少一个相当明显的选项。 该月的第一周是从该月的第一天开始的 7 天。 因此,在您的示例中,第一周将是 1 号星期二到 7 号星期一。 这样,第一周到第四周将始终完全包含在该月内,只有第五周会交叉。

There's a fairly obvious option you are missing. The first week of the month is the seven days starting with the first day of the month. Hence, in your example, the first week would be Tuesday, the 1st through Monday, the 7th. This way, the first through 4th weeks would always be fully contained within the month, and only the 5th week would cross over.

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