I have a scheduled cloud function which runs in Europe/Berlin timezone. Long story short, I need to get day number in a year.
I've used this code for that:
https://stackoverflow.com/a/8619946/4195212
At time when I'm writing this if I run a code in the snippet inside the answer posted above it will show me 221 (which is correct). But in my cloud function it is 220.
I thought I need to set a timezone correctly, which I did. But still it shows the wrong day number.
What is wrong here?
exports.scheduledFunction2 = functions.region('europe-west3').pubsub.schedule('every minute').timeZone("Europe/Berlin").onRun((context) => {
var now = new Date();
var start = new Date(now.getFullYear(), 0, 0);
var diff = (now - start) + ((start.getTimezoneOffset() - now.getTimezoneOffset()) * 60 * 1000);
var oneDay = 1000 * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
console.log('Day of year: ' + day); // prints 220
})