contributte / forms

:sparkles: Extra contrib to nette/forms (@nette)
https://contributte.org/packages/contributte/forms.html
MIT License
9 stars 4 forks source link

DateTime, Date and Time inputs #31

Closed MartinMystikJonas closed 2 years ago

MartinMystikJonas commented 2 years ago

Features

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.

f3l1x commented 2 years ago

I think general approach is good. Maybe Parser can be interface, wdyt?

MartinMystikJonas commented 2 years ago

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.

MartinMystikJonas commented 2 years ago

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?

f3l1x commented 2 years ago

Ad parser) Agreed.

Ad native inputs) Agreed. I think it's OK.

MartinMystikJonas commented 2 years ago

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.

MartinMystikJonas commented 2 years ago

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.

MartinMystikJonas commented 2 years ago

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) :-)

dakur commented 2 years ago

@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!

MartinMystikJonas commented 2 years ago

I will fix it.

MartinMystikJonas commented 2 years ago

Typo with DaetTime fixed