Closed MartinMystikJonas closed 2 years ago
I think general approach is good. Maybe Parser can be interface, wdyt?
I am not sure there would ever be need for different implementations because this parser is configurable for any format. I made it to separate class so it can be eventually reused in other date/time inputs implementations. For example it could be eventually used by date/time inputs in contributte/forms-bootstrap instead of writing custom parser there.
Main decision I was not sure about was how to differentiate between creating native html date/datetime-local inputs or just normal text inputs allowing custom formats parsed server-side. I decided it would create native html/date/local-datetime if format was ommited and normal text inout if format(s) are specified. Do oyu think it is ok?
Ad parser) Agreed.
Ad native inputs) Agreed. I think it's OK.
One more thing. I saw that nextras DateTimeInput supports callback parsers for non-standard formats. Do you think we should support it too? It would not be too much complication. Parser would simply accept formats both as string or callback.
I added one more feature I was missing in one of our prtojects. Ability to specify input time zone (zime zone in which user enters values) and automatically convert DateTime objects passed to set Value or validation rules to this timezone.
Also we can then either convert value to default timezone or return in with correct timezopne set. Which would you think is better? Existing datetime inputs does not handle this.
Now it is fully tested and documented. It should be finished and ready for merge.
Someone please check docs if it is understandable a and check for typos (I have problem with typos escecially when I write in english) :-)
@MartinMystikJonas There is DaetTime
instead of DateTime
in FQNs in the docs everywhere. Sorry, I can't update it now.
And thank you for your effort!
I will fix it.
Typo with DaetTime fixed
Features
->setValueType(\Nette\DateTime::class)
->setValueType([\Brick\DateTime\LocalDate::class, 'fromNativeDateTime'])
)$control->setHtmlAttribute('class', 'custom-class');
new DateTimeInput("Date") // type="datetime-local"
new DateTimeInput("Date", 'd.m.Y H:i') // type="text"
->setFormats(['d.m.Y H:i', 'Y-m-d H:i']);
<input type="text" data-format="d.m.Y H:i" data-settings="{...json...}"
handle different input/server timezone
->setInputTimezone(new DateTimeZone('America/New_York'))
I prepared first draft of DateTime inputs as discussed in #7
Please check it and let me know if you like my general approach. If it would be ok I will add tests and documentation.