diff --git a/CD220Labs/http_server/index-with-require.js b/CD220Labs/http_server/index-with-require.js index dcf15392b..fa8436ed6 100644 --- a/CD220Labs/http_server/index-with-require.js +++ b/CD220Labs/http_server/index-with-require.js @@ -1,4 +1,4 @@ - // Import the HTTP module +// Import the HTTP module const http = require('http'); // Import the 'today' module @@ -7,8 +7,24 @@ const today = require('./today'); // Define the request listener function const requestListener = function (req, res) { res.writeHead(200); // Set the status code to 200 (OK) + let hour = today.getHours(); + let date = today.getDateObject().toLocaleString('en-US', { timeZone: 'America/New_York' }).slice(0, 9); + + let greeting = 'Food is important!'; + if (hour > 7 && hour < 12) { + greeting = 'Have you had breakfast yet?'; + } else if (hour >= 12 && hour < 15) { + greeting = 'Have you had lunch yet?'; + } else if (hour >= 15 && hour < 19) { + greeting = 'Have you had a snack yet?'; + } else if (hour >= 19 && hour < 23) { + greeting = 'Have you had dinner yet?'; + } else { + greeting = 'Its late, you should be sleeping!'; + } + // Send the response with the current date from the 'today' module - res.end(`Hello, World! The date today is ${today.getDate()}`); + res.end(`Hello, World! \nThe date today is ${date} \n${greeting}`); }; // Define the port number diff --git a/CD220Labs/http_server/index.js b/CD220Labs/http_server/index.js index c5655cfc0..e97e2dcb5 100644 --- a/CD220Labs/http_server/index.js +++ b/CD220Labs/http_server/index.js @@ -1,10 +1,10 @@ - // Import the HTTP module +// Import the HTTP module const http = require('http'); // Define the request listener function const requestListener = function (req, res) { res.writeHead(200); // Set the status code to 200 (OK) - res.end('Hello, World!'); // Send the response "Hello, World!" + res.end('Hello, World!\n'); // Send the response "Hello, World!" }; // Define the port number diff --git a/CD220Labs/http_server/today.js b/CD220Labs/http_server/today.js index 43e54d2b3..b2ccd857f 100644 --- a/CD220Labs/http_server/today.js +++ b/CD220Labs/http_server/today.js @@ -1,6 +1,23 @@ - // Export a function named 'getDate' from the module +/* +// Export a function named 'getDate' from the module module.exports.getDate = function getDate() { // Get the current date and time in the timezone "Australia/Brisbane" let aestTime = new Date().toLocaleString("en-US", {timeZone: "Australia/Brisbane"}); return aestTime; // Return the formatted date and time }; +*/ +module.exports = { + getDate: function getDate() { + return new Date().toLocaleString("en-US", { timeZone: "America/New_York" }); + }, + getHours: function getHour() { + let dateObj = new Date().toLocaleString('en-US', { timeZone: 'America/New_York' }); + let tempDate = new Date(dateObj); + return tempDate.getHours(); + }, + getDateObject: function getDateObject() { + let dateObj = new Date(); + let aestTime = new Date(dateObj.toLocaleString('en-US', { timeZone: 'America/New_York' })); + return aestTime; + } +};