You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow users to override the default date parsing and formatting that Ca11y does.
Implementation:
This could be entirely left to userland code as Dan outlined in #13.
importCa11yfrom'ca11y'importstrftimefrom'strftime'constmyInput=document.querySelector('.input')// user defines format/parse methods and is responsible for calling themfunctionformat(date){returnstrftime('%F %T',date)// simple e.g.}functionparse(str){constdate=newDate(str)// simple e.g.return{valid: !isNaN(date),// basic validationdate: date}}functioncreateChangeHandler(instance){returnfunctiononChange(e){constresult=parse(e.target.value)if(result.valid){instance.setDate(result.date)}}}constoptions={// when a day is selected, propagate the change back to the inputonDaySelected(date){myInput.value=format(date)}}// create a new Ca11y instance, lib is responsible for merging defaults with optionsconstcalendar=newCa11y(options)// tie changes to the input back to Ca11ymyInput.addEventListener('change',createChangeHandler(calendar),false)
The text was updated successfully, but these errors were encountered:
In addition to returning the js date object, I'm going to return the following key/value pairs that should make it pretty easy to format your date however you want.
key
value
d
Day of the month as digits; no leading zero for single-digit days.
dd
Day of the month as digits; leading zero for single-digit days.
ddd
Day of the week as a three-letter abbreviation.
dddd
Day of the week as its full name.
m
Month as digits; no leading zero for single-digit months.
mm
Month as digits; leading zero for single-digit months.
mmm
Month as a three-letter abbreviation.
mmmm
Month as its full name.
yy
Year as last two digits; leading zero for years less than 10.
Related to #13
Purpose:
Allow users to override the default date parsing and formatting that Ca11y does.
Implementation:
This could be entirely left to userland code as Dan outlined in #13.
The text was updated successfully, but these errors were encountered: