Mongo 和 Luxon 中的 weekNumber 之间的差异
Differences between weekNumber in Mongo and Luxon
我正在对日期进行一些 mongo 聚合,运行 遇到了一个有趣的问题,即来自 mongo 的 $week return 不同于weekNumber return来自 Luxon。
在下面的代码片段中,$week 来自 mongo returns 47,而来自 Luxon returns 48.
的 weekNumber
有没有办法将两者归一化,使给定日期 return 与 $week/weekNumber 相同?
我可以从 Luxon 编辑的 return 值中减去一个,但我想了解为什么响应不同,以确定是否有更多 appropriate/elegant 的修复方法这个。
MONGO:
[{
'$match': {
'date': {
'$eq': datetime(2020, 11, 23, 0, 0, 0, tzinfo=timezone.utc)
}
}
}, {
'$project': {
'w': {
'$week': '$date'
}
}
}]
LUXON:
import { DateTime } from "luxon";
var week = DateTime.fromJSDate(new Date(2020,10,23)).weekNumber;
console.log(week);
查看文档:
Week calendar: For ISO week calendar attributes, see the weekYear, weekNumber, and weekday accessors.
Returns the week of the year for a date as a number between 0 and 53.
Weeks begin on Sundays, and week 1 begins with the first Sunday of the year. Days preceding the first Sunday of the year are in week 0. This behavior is the same as the “%U” operator to the strftime standard library function.
如果您想根据 ISO-8601 获取周数,请使用 $isoWeek():
Returns the week number in ISO 8601 format, ranging from 1 to 53. Week numbers start at 1 with the week (Monday through Sunday) that contains the year’s first Thursday.
在 Luxon 中似乎没有相当于 MongoDB 的 $week
我正在对日期进行一些 mongo 聚合,运行 遇到了一个有趣的问题,即来自 mongo 的 $week return 不同于weekNumber return来自 Luxon。
在下面的代码片段中,$week 来自 mongo returns 47,而来自 Luxon returns 48.
的 weekNumber有没有办法将两者归一化,使给定日期 return 与 $week/weekNumber 相同?
我可以从 Luxon 编辑的 return 值中减去一个,但我想了解为什么响应不同,以确定是否有更多 appropriate/elegant 的修复方法这个。
MONGO:
[{
'$match': {
'date': {
'$eq': datetime(2020, 11, 23, 0, 0, 0, tzinfo=timezone.utc)
}
}
}, {
'$project': {
'w': {
'$week': '$date'
}
}
}]
LUXON:
import { DateTime } from "luxon";
var week = DateTime.fromJSDate(new Date(2020,10,23)).weekNumber;
console.log(week);
查看文档:
Week calendar: For ISO week calendar attributes, see the weekYear, weekNumber, and weekday accessors.
Returns the week of the year for a date as a number between 0 and 53.
Weeks begin on Sundays, and week 1 begins with the first Sunday of the year. Days preceding the first Sunday of the year are in week 0. This behavior is the same as the “%U” operator to the strftime standard library function.
如果您想根据 ISO-8601 获取周数,请使用 $isoWeek():
Returns the week number in ISO 8601 format, ranging from 1 to 53. Week numbers start at 1 with the week (Monday through Sunday) that contains the year’s first Thursday.
在 Luxon 中似乎没有相当于 MongoDB 的 $week