一个月的第一周/最后一周是星期几?
如果有人说某个月的第一周或最后一周发生了什么事,你会如何定义这个时间跨度?
背景
我正在开发一个需要以直观的方式处理此类事情的库,但我的直觉并不支持一种情况或另一种情况。
我可以让它选择不同的行为,但仍然需要一个好的默认值。
我将随机选择一个月份: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
(注意:我假设一周从星期日开始,但也可以在星期一提出问题)
举一个具体的例子, 该月的第一周?
- 6 月 29 日 - 7 月 5 日 -- 包括第一周
- 7 月 6 日 - 12 日 -- 该月的第一周
第二周只是第一次之后7天对吗?
该月的最后一周是多长时间?
- 7 月 27 日 - 8 月 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?
- June 29 - July 5 -- the week that includes the first
- 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?
- July 27 - Aug 2 -- ditto but the last day
- July 20 - 26 -- ditto but the last week
Non wiki comments welcome
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
没有答案,因为即使在一个国家内部情况也有所不同。
但是,< 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:
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.
如果您正在构建一个库,您应该允许用户选择他们想要如何处理它,方法是返回该月的第一周/最后一周的完整/部分周,或者传递一个参数来指示您是否想要完整/部分周。部分周。 如果您提供不需要规范的方法,请清楚地记录默认值。
或者
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.
Or
的一周
The first week of the month is the week that includes the first
间的第一周
The first week of the month is the first week that is all the way int the month
最后一天的那一周
The last week of the month is the week that includes the last day
日期间的最后一周
The last week of the month is the last week that is all the way int the month
该月的第一周是第 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
:)
我的定义是第一周是该月第一个工作日的那一周,
同样,最后一周是该月最后一个工作日的那一周。
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.
该月的第一周是指拥有 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)
您缺少一个相当明显的选项。 该月的第一周是从该月的第一天开始的 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.