Skip to content

Instantly share code, notes, and snippets.

@louicoder
Last active April 28, 2022 07:53
Show Gist options
  • Save louicoder/5366f7aa94825fa8a6242433e829df6e to your computer and use it in GitHub Desktop.
Save louicoder/5366f7aa94825fa8a6242433e829df6e to your computer and use it in GitHub Desktop.
moment Helper Functions
/**
* @param startDate {String} format 'YYYY-MM-DD'
* @param endDate {String} format 'YYYY-MM-DD'
* @returns Array [] String
*
*/
const enumerateDaysBetweenDates = function (startDate, endDate) {
// Start Date format should be YYYY-MM-DD
// End Date format should be YYYY-MM-DD
var dates = [];
// Get the day to start from.
var currDate = moment(startDate).startOf('day');
// Add one day to the end date to return the end date as well
var lastDate = moment(endDate).startOf('day');
// Get the difference in days
// < 0 to exclude the end date, but use < 1 to include last day.
while (currDate.add(1, 'days').diff(lastDate) < 1) {
// console.log(moment(currDate).format('DD-MM-YYYY'));
dates.push(moment(currDate).format('DD-MM-YYYY'));
}
return dates;
};
const createDateWithOffset = () => moment().toISOString();
const getActualDateInTimezone = (date) => {
// pass Iso String
// moment().toISOString()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment