Created
February 10, 2022 22:29
-
-
Save robjshaw/8aca78739504d2a5744a6bea7b332238 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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