The US federal holiday for 2028 New Year's Day falls in 2027
2028年1月1日是星期六。根据美国联邦规定,落在星期六的节假日会在前一个星期五补休。因此,2028年元旦的休息日是2027年12月31日星期五。
January 1, 2028 is a Saturday. Under the US federal rule, a holiday that lands on a Saturday is observed on the Friday before. So the day off for New Year’s 2028 is Friday, December 31, 2027.
这一日期打破了我业务日代码中的一个假设:“今年的节假日发生在今年”。美国人事管理办公室(OPM)按年份发布节假日时间表。其2028年的表格以“12月31日星期五 * 元旦”开头,而那个星期五属于2027年。如果你通过循环一年的规则并保留该年份内的日期来构建节假日列表,就会漏掉它。结果会产生一天的偏差。
That one date broke an assumption in my business-days code: “this year’s holidays happen in this year.” Where it shows up OPM publishes holiday schedules by year. Its 2028 table starts with “Friday, December 31 * New Year’s Day”, and that Friday falls in 2027. If you build a holiday list by looping over one year’s rules and keeping dates inside that year, you drop it. The result is off by one.
我的计算器统计出2027年有249个美国联邦工作日。那一年有12个工作日联邦节假日,而不是通常的11个。它有两个元旦:2027年1月1日星期五(属于当年),以及2027年12月31日星期五(属于2028年)。
My calculator counts 249 US federal business days in 2027. That year has 12 weekday federal holidays, not the usual 11. It gets two New Year’s days: Friday, January 1, 2027 for its own, and Friday, December 31, 2027 for 2028’s.
解决方法:当我为Y年生成节假日时,我也会检查Y+1年的1月1日:// 如果明年的1月1日是星期六,其补休日就是今年的12月31日。const nextNY = new Date(Date.UTC(year + 1, 0, 1)); if (nextNY.getUTCDay() === 6) { list.push([“New Year’s Day (observed)”, new Date(Date.UTC(year, 11, 31))]); } // 如果今年的元旦假期被移到了去年,则将其剔除。return list.filter(([, d]) => d.getUTCFullYear() === year);
The fix When I generate holidays for year Y, I also check January 1 of year Y+1: // if next year’s Jan 1 is a Saturday, its observed day is Dec 31 of this year const nextNY = new Date(Date.UTC(year + 1, 0, 1)); if (nextNY.getUTCDay() === 6) { list.push([“New Year’s Day (observed)”, new Date(Date.UTC(year, 11, 31))]); } // and drop this year’s Jan 1 holiday if it was moved back into last year return list.filter(([, d]) => d.getUTCFullYear() === year);
过滤器也很重要。2022年,1月1日也是星期六,所以补休日是2021年12月31日。它应该计入2021年的总数,而不是2022年。
The filter matters too. In 2022, January 1 was also a Saturday, so the observed day was December 31, 2021. It belongs in 2021’s count, not 2022’s.
英国的做法则相反。英格兰和威尔士将周末的银行假日向后顺延至下一个工作日。在2027年底,情况如下:圣诞节(星期六)补休至12月27日星期一;节礼日(星期日)补休至12月28日星期二;2028年元旦(星期六)补休至2028年1月3日星期一。
The UK does it the other way England and Wales move a weekend bank holiday forward, to the next weekday. In late 2027 that gives: Christmas Day (Saturday) is observed Monday, December 27 Boxing Day (Sunday) is observed Tuesday, December 28 New Year’s Day 2028 (Saturday) is observed Monday, January 3, 2028
我根据GOV.UK的银行假日数据核对了这些日期,我的规则得出了相同的日期。一个国家将节假日提前跨年,而另一个国家则将其推后,因此“如果是星期日就加1天”并不是一个通用的规则。
I checked those against the GOV.UK bank holidays feed, and my rules produce the same dates. One country pulls the day back across the year line and the other pushes it forward, so “add 1 if Sunday” is not a universal rule.
我的心得:构建跨度为多年的节假日映射,而不是一次只构建一年,并在之后进行过滤。特意测试边界年份。2021/2022年和2027/2028年是需要保留在测试文件中的年份。在有官方数据源时,请进行对比。GOV.UK发布JSON格式数据;OPM则按年份发布表格。如果你想在不编写代码的情况下检查日期范围,我构建的计算器显示了它跳过了哪些节假日:业务日计算器。各国的年度总数在这里:一年中的工作日。
What I took from it Build holiday maps for a range of years, not one year at a time, and filter afterward. Test the boundary years on purpose. 2021/2022 and 2027/2028 are the ones to keep in your test file. Compare against the official feed when one exists. GOV.UK publishes JSON; OPM publishes a table per year. If you want to check a date range without writing the code, the calculator I built shows which holidays it skipped: Business Days Calculator. The yearly totals by country are here: Business days in a year.