I'm creating a suuuuuper Node.js microservice that takes in either a date in the format "MON DD, YYYY" or a unix timestamp and returns both the date and timestamp as JSON. I thought it worked but it turns out some of my basic String methods seem to be running asynchronously. I have posted the main block of code below for your perusal. I'm very new to Node so I'm not sure if it just has to do with Node itself.
Here's my main code for controlling the service. I pass the date in (Jan 30, 2017) and then check it for certain data to determine if it's a timestamp or formatted. This is just if it's a formatted date. I am having issues with the regex: it claims it cannot .join() the 'day' variable because the match returns null, even though it does not in separate testing (logging the result). Any ideas?
module.exports = function (date) {
var month = "";
var day = "";
var year = "";
var naturalDate = "";
var unixTime = "";
// check to see if there's text to decipher
if (date.match(/[a-zA-Z]/g)) {
month = date.match(/[a-zA-Z]/g).join("").toLowerCase();
month = checkMonth(month);
day = date.match(/ \d{1,2}\,/g).join("").replace(/ /, "").replace(/\,/, "");
console.log("DAY IS: " + day);
day = checkDay(day, month);
year = date.match(/\d{4}/).toString();
naturalDate = month + " " + day + ", " + year;
console.log("NATURAL DATE: " + naturalDate);
unixTime = convertUnix('natural', naturalDate);
}
via Jesse Reitz
No comments:
Post a Comment