Reputation: 11030
When a user selects an end day on my calendar component, I have the following:
moment(currentTime.end).endOf('day').format('YYYY-MM-DD');
Usually the date range is preset but users can also adjust the time range within the date range.
If a user sets the end time to 23:59:59, I want to add an additional second and give them 24 hours. Is there a way in moment.js to recognize when a certain date set to the endOfDay
, and is there a way to add a second?
Upvotes: 0
Views: 875
Reputation: 958
use
.add(1, 'second')
to add a seconduse
.format('HH:mm:ss') === '23:59:59
to check is time end of day
e.g.:
var currentTime = {start: xxx, end: xxx};
// get the endTime by HH:mm:ss
var endTime = moment(currentTime.end).format('HH:mm:ss');
if (endTime === '23:59:59') {
// If true add one second and return the format you need
endTime = moment(currentTime.end).add(1, 'second').formet('YYYY-MM-DD');
} else {
// If false just return the format you need
endTime = moment(currentTime.end).formet('YYYY-MM-DD');
}
Upvotes: 2