Skip to content

Instantly share code, notes, and snippets.

@robjshaw
Created February 10, 2022 22:29
Show Gist options
  • Select an option

  • Save robjshaw/8aca78739504d2a5744a6bea7b332238 to your computer and use it in GitHub Desktop.

Select an option

Save robjshaw/8aca78739504d2a5744a6bea7b332238 to your computer and use it in GitHub Desktop.
exports.handler = function(context, event, callback) {
// With timezone:
// In Functions/Configure, add NPM name: moment-timezone, version: 0.5.14
// Timezone function reference: https://momentjs.com/timezone/
let moment = require('moment-timezone');
//
// timezone needed for Daylight Saving Time adjustment
let timezone = event.timezone || 'Australia/Sydney';
console.log("+ timezone: " + timezone);
//
const hour = moment().tz(timezone).format('H');
const dayOfWeek = moment().tz(timezone).format('d');
if ((hour >= 7 && hour < 20) && dayOfWeek <= 6) {
// "open" from 7am to 8pm, AEST.
response = "open";
} else {
response = "after";
}
theResponse = response + " : " + hour + " " + dayOfWeek;
console.log("+ Time request: " + theResponse);
callback(null, theResponse);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment