Date/time Custom Attributes cant be save empty?

Permalink
I've created two custom attributes using type DATE/TIME and the input don't save empty data, it always put back 1969-12-31 when reediting the properties.

Something I miss?

olacom
View Replies:
olacom replied on at Permalink Reply
olacom
anyone?
tbcrowe replied on at Permalink Reply
tbcrowe
You need to keep in mind that dates are stored essentially as an integer value which is the number of seconds from an epoch (technically January 1, 1970). Thus if you don't enter a value its going to default to 0 or NULL.

You can change how this value displays by copying the file concrete/models/attribute/types/date_time/controller.php to models/attribute/types/date_time/controller.php and changing the getDisplayValue() method to whatever value you want to display in that special case.
SkyBlueSofa replied on at Permalink Reply
SkyBlueSofa
The issue, I think, is that the date is empty but the time is not. There is code to check for empty values, but for datetime there is never an empty value.

I would think that if there was no date, then the whole datetime field should be NULLed out. Have there been any conversations on this that you know of?
tbcrowe replied on at Permalink Reply
tbcrowe
I'm not aware of any other discussions on this subject. I based my response on the short problem description above.
olacom replied on at Permalink Reply
olacom
This is what I was expecting that if you save a date field with empty data, it will save it as NULL.

There is not much info about this in the forum.
jordanlev replied on at Permalink Reply
jordanlev
If you look at the table definition in MySQL for "atDateTime", you'll see that the value field has a default value of "0000-00-00 00:00:00". So... you could try changing this to not have a default value (or a default value of NULL) -- BUT this might have unintended consequences elsewhere in code (if for example there is some other code that assumes the value is never null). But worth a try I guess.

Otherwise you need to do what tbcrowe suggests and alter the code that gives you the values so it converts 0 to null in php.
SkyBlueSofa replied on at Permalink Reply
SkyBlueSofa
Are you trying to save date, time, or datetime information?
tbcrowe replied on at Permalink Reply
tbcrowe
The Date/Time attribute saves its data in the same format independently of the output type (date, time or datetime).

I looked over the code I referenced above some more, though, and you may also need to change the form() method in that file.
olacom replied on at Permalink Reply
olacom
Modifying is not a problem but don't you agree that this is something that should be arrange in the Date attribute type ?

I mean in the core.

It's just confusing when a user delete the data of a custom date attribute and when he edit it back, it as save 1969-12-3 instead of NULL.
jordanlev replied on at Permalink Reply
jordanlev
Oh man, I have a list of probably 100 things that I think should be fixed/changed in the core :)

You should file a bug for this and provide as much detail as possible -- there are just so many parts of the system it's impossible for Andy and team to know about everything unless people bring it to their attention.

Better yet, if you're a programmer you could code up a solution and test it out, and if it works you can make a patch and submit that (thus greatly increasing the likelihood that the change will get implemented).