'Unable to change timestamp to date time
{ "meeting": { "queue": "Waiting in line", "template": "The Technical Template" }, "assignee": "John Snow", "type": "Auto", "timestamps": [ { "starttime": 1616358840, "future": "yes" }, { "endtime": 1616361540, "future": "yes" } ], "name": "Chili Piper Technical Call", "meeting_id": "30075445" }
Question is: Based on the configuration, when does the meeting start in PST? What is the meeting duration?
Any help will be greatly appreciated.
Solution 1:[1]
GMT:
Start: Sun Mar 21 2021 20:34:00 GMT+0000
End: Sun Mar 21 2021 21:19:00 GMT+0000
Duration: 45min
PST=GMT-8
or something like this:
db.collection.aggregate([
{
$project: {
timestamps: {
"$mergeObjects": "$timestamps"
}
}
},
{
$project: {
startTime: {
$toDate: {
$multiply: [
{
$add: [
"$timestamps.starttime",
-28800
]
},
1000
]
}
},
endTime: {
$toDate: {
$multiply: [
{
"$add": [
"$timestamps.endtime",
-28800
]
},
1000
]
}
}
}
},
{
$project: {
_id: 0,
startTime: 1,
endTime: 1,
durationMinutes: {
$divide: [
{
$subtract: [
"$endTime",
"$startTime"
]
},
60000
]
}
}
}
])
result in PST:
{
"durationMinutes": 45,
"endTime": ISODate("2021-03-21T13:19:00Z"),
"startTime": ISODate("2021-03-21T12:34:00Z")
}
explained:
- merge the start & end timestamps in single object.
- Convert the GMT unix timestamp-PST offset(8x60x60) to ISODate
- Project the start and end ISODate and calculate the duration in minutes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
