Taking time value and returning a value that will pass a moment().isValid() check
Solution 1:
Docs: set, startOf.
const input = '14:29';
const [hour, minute] = input.split(':');
const myMoment = moment()
.set({ hour, minute })
.startOf('minute');
console.log(
{ myMoment, isValid: myMoment.isValid() }
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>
Note: this will respect the browser timezone meaning different users will get different moments in time, depending on their system's currently set timezone.
To set a particular timezone you might want to use .tz()
. Docs: moment timezone.