In a View I’m developing, my aggregation includes:
$addFields: {
adjustedUTC: {
$dateFromParts: {
year: {
$year: {
date: new Date(),
timezone: "$timezone",
},
},
month: {
$month: {
date: new Date(),
timezone: "$timezone",
},
},
day: {
$dayOfMonth: {
date: new Date(),
timezone: "$timezone",
},
},
hour: {
$hour: {
date: "$startDateUTC",
timezone: "$timezone",
},
},
minute: {
$minute: {
date: "$startDateUTC",
timezone: "$timezone",
},
},
timezone: "$timezone",
},
},
}
The adjustedUTC field is set by a $dateFromParts expression that needs to account for the timezone of the event data. This code is doing what I want, but all of the setting of timezone fields seems redundant when I set it for the entire $dateFromParts expression and each part field. I thought I should be able to remove the latter entries, but then the code fails. Likewise, if I remove the option for the entire $dateFromParts expression, the logic fails.
What is the difference between these timezone options that makes all of them required?
And second, I’d welcome other ideas to simplify the creation of adjustedUTC. It does need to account for both the current date and the time contained in $startDateUTC.