I'm facing a simple -yet my brain can't come up with a solution - problem involving entering/saving time entries in js. Allow me to explain:
I an input in a form to enter business hours:
....
from
<input required type="time" id="Monday" value={monday.openhours}
placeholder="from"/> To
<input required type="time" id="Monday" value={monday.closehours}
placeholder="to"/>
.....
I wanted to have min and max entered for the user between 10am and 10pm so I created an array that has the following:
let defaultopenhours = "10"
let defaultclosehours = "22"
let monday = {"weekdayname":"Monday","weekdaynumber":1,"openhours":defaultopenhours,"closehours":defaultsclosehours}
let tuesday = ...same as monday so on for the rest of weekdays {wednesdy to sunday}
let schedule = []
I would then push the days into the schedule array and store it in my db. Focus on one part with me here which is the defaultopenhours var and defaultclosehours var.
When I assign 10:00 as a value and open my html to enter time, the input fields are suppose to be populated with 10:00am to 10:00pm (22:00pm) but I get this in my console:
The specified value "22" does not conform to the required format. The format is "HH:mm", "HH:mm:ss" or "HH:mm:ss.SSS" where HH is 00-23, mm is 00-59, ss is 00-59, and SSS is 000-999.
I've never needed to work with time before in js. I'm aware of momentjs and other but I want to learn how to do it in pure js. So I'm sure there are ways to solve this problem but after readying for 2 hours and trying to enter the time values in Number(), parseInt(), parseFloat() and all kind of functions I still get that error.
Do I need to use different parts
let h = 10
let m = 00
defualt = Number(h+":"+m) or something?
To all the law abiding citizens out there who will say that this question exists in a different corner of the internet, I hear you, I just couldn't find it. So please let others answer the question if you don't have time for me. If you do, I'm grateful for the education you share with me.
Clearly the input accepts a specific format, so how to store my values so that format is accepted by the time input type?
So my question to all the js ninjas out there, how to assign the value 10:00 or 10:00 (which is 22:00) to defaultopenhours and defaultclosehours variables?