I am currently working on an app. Working with trongate is a breathtaking pleasure (mostly).
But working with dates brought me great confusion.
To further understand this, I created a new app with a single module (people) with two fields in the database: name (type varchar) and date of birth (type date).
If I try to enter a first person and I click on the date entry field I can choose a date with the date picker and the date in the entry field is displayed in the pattern dd/mm/yyyy (24/04/2023).
However, after submit, the person information screen shows the date Thursday 1st January 1970.
When I then return to the update window the date is displayed as 1970-01-01 and then when I click in the field to change the date the date picker is displaying May 24 1906 as the active date.
If I use phpmyadmin to enter a date in the record (April 30, 1975) and then view it in the app the same date is shown under Manage People (Wednesday 30th April 1975), just like in Person Information, but after going to Update Details the date is shown as 1975-04-30
and the date picker jumps to August 27, 1935.
My guess is that the way the dates are displayed in the form field is wrong.
Do I need to change the formatting of the form field Date of Birth? How should I do that?
I tried to find explanatory details in the docs and in the youtube videos but did not find a solution.
I hope someone is able and willing to point me in the right direction.
---
one addition:
I managed to get the correct date format in the form field on the Update Person Information page by adding one line in the create function of the modules controller after the get_data_from_db:
but as soon as I use the date picker the format gets changed from dd-mm-yyyy to mm/dd/yyyy. February 4th is changed to April 2nd.
I would really like to know how to solve this.
confused by date handling
3 years ago
3 years ago
#1
3 years ago
#2
Hello,
Have a look in the following file:
public/js/trongte-datetime.js
Dan
Have a look in the following file:
public/js/trongte-datetime.js
Dan
3 years ago
#3
G'day jot,
There are a few quirks with the 'Date-picker' and some of the code generated from the Desktop app - which DC knows about and has on his 'To-Do' list for fixing.
By default, the validation rules are checking for 'valid_datepicker_us' in the submit() method of your People.php controller:
change it to 'valid_datepicker_eu', otherwise you get a validation error of:
once changed, you should get this from the _POST by adding json($data,1); after $data = $this->_get_data_from_post();
And there is also a problem with strtotime() where it gets confused with dd/mm/yyyy formats like "24/04/2023" and will return 'null' or "1970-01-01". A quick fix is to get rid of the slashes and swap them with dashes:
$data should now equal:
or "date_of_birth" = null if nothing was entered.
Now in the create() method, convert the stored database date "2023-04-24" back into a format the date-picker can understand, otherwise, you will get the strange behaviour you are seeing:
There are a few more fixes needed for null date values
Another is the inability to edit the date in the input form, like changing the year without cycling through it with the datepicker - the issue here is the javascript is resetting the cursor and stopping the edit. I did write a fix for this a while ago and may even be here on the help_bar or on the SCA forum.
As you can see there are a few issues needing fixing...
Cheers,
Si
There are a few quirks with the 'Date-picker' and some of the code generated from the Desktop app - which DC knows about and has on his 'To-Do' list for fixing.
By default, the validation rules are checking for 'valid_datepicker_us' in the submit() method of your People.php controller:
change it to 'valid_datepicker_eu', otherwise you get a validation error of:
once changed, you should get this from the _POST by adding json($data,1); after $data = $this->_get_data_from_post();
And there is also a problem with strtotime() where it gets confused with dd/mm/yyyy formats like "24/04/2023" and will return 'null' or "1970-01-01". A quick fix is to get rid of the slashes and swap them with dashes:
$data should now equal:
or "date_of_birth" = null if nothing was entered.
Now in the create() method, convert the stored database date "2023-04-24" back into a format the date-picker can understand, otherwise, you will get the strange behaviour you are seeing:
There are a few more fixes needed for null date values
Another is the inability to edit the date in the input form, like changing the year without cycling through it with the datepicker - the issue here is the javascript is resetting the cursor and stopping the edit. I did write a fix for this a while ago and may even be here on the help_bar or on the SCA forum.
As you can see there are a few issues needing fixing...
Cheers,
Si
3 years ago
#4
Dear Dan and Dafa,
Thank you very much for your responses. They were both very helpful and complementary.
Just last week David urged us to "*** PLEASE TALK TO US AS IF WE'RE IDIOTS ***",but that is certainly completely misplaced in this case. The contributions were friendly, to the point and highly appreciated. And above all correct and effective.
With the modifications in trongate-datetime.js, I was able to adapt the date picker to Dutch.
However, I got the most out of DaFa's replies, many thanks!
For those reading this tread to adapt dates to other languages, I want to add a few more lines of code:
In manage.php:
and in show.php:
Perhaps needless to say: for this to work the INTL extension for php needs to be installed and activated in php.ini (took me some time to figure out)
Thank you very much for your responses. They were both very helpful and complementary.
Just last week David urged us to "*** PLEASE TALK TO US AS IF WE'RE IDIOTS ***",but that is certainly completely misplaced in this case. The contributions were friendly, to the point and highly appreciated. And above all correct and effective.
With the modifications in trongate-datetime.js, I was able to adapt the date picker to Dutch.
However, I got the most out of DaFa's replies, many thanks!
For those reading this tread to adapt dates to other languages, I want to add a few more lines of code:
In manage.php:
and in show.php:
Perhaps needless to say: for this to work the INTL extension for php needs to be installed and activated in php.ini (took me some time to figure out)
1 years ago
#5
I have been trying to read this content on my iPhone, with all good intentions, but despite the design being responsive to the screen size, the content of the post is not, it runs right off the page into the black background, right off the viewport on the right side.
I prepared a screen shot, but there is no way to add it to this post. Sorry.
I prepared a screen shot, but there is no way to add it to this post. Sorry.
1 years ago
#6
Hi Charles, the forums should be looking a lot better now. It's not perfect but give it some to polish out these quirks