FWIW, these constants are not universal. In Postgres (and MySQL since 5.7) the date+time types have optional sub-second precision - which the "Y-m-d H:i:s" pattern will fail to parse.
Another common case in Postgres is date+time with timezone, e.g. used for scheduling/calendar applications etc. - yet another pattern. Not an argument against having these constants, at all, but they've already been defined everywhere in userland where needed, so, as others have said, I'm not really sure what adding them to the core will accomplish. We'll likely still need other similar constants for other formats. > It's surely easy to implement them in userland but that would require > either global constants or a class in userland specifically for that > purpose I think it's more common to declare them in the class that needs them - for such a small dependency as a date/time pattern, I would honestly prefer to have them plainly visible, declared in the relevant class, next to other related constants, such as date/time regex for input-validation, etc. Likewise, I'd prefer to have minute/hour/day constants defined where needed - I find that const DAY = 24*60*60 is more easily parsed and understood than a predefined const DAY = 86400. That's all based on personal preference - but namely because it is largely a matter of convenience/preference/opinion, and since it's no burden to declare these at all, perhaps these are good reasons to leave it in userland. On Thu, Mar 2, 2017 at 4:46 PM, Crocodile <crocodil...@gmail.com> wrote: > While I agree with everything you're saying, I also think it could still be > worth it to have those constants in core for the following reasons: > > 1. MINUTE, HOUR and DAY are particularly often used, 99.999% of the time in > a context where it does not matter if a minute has 60 seconds or not, or if > a day has 24h or not. Particularly often used to specify cache lifetime, > for example. > 2. It's surely easy to implement them in userland but that would require > either global constants or a class in userland specifically for that > purpose. Both ways are easy, but these constants I see in virtually any > project, so for me it would be handy to have them in DateTime. > > But of course, I don't see it as a must-have, just as nice-to-have. > > Cheers, > Victor > > On Thu, Mar 2, 2017 at 4:03 PM Andreas Heigl <andr...@heigl.org> wrote: > > > Hi Victor. > > > > > > Am 02.03.17 um 15:48 schrieb Crocodile: > > > Hello internals, > > > > > > A similar question should have been asked already but I haven't found > > > anything so far when googling: I think DateTime class should have the > > > following constants in addition to those already existing: > > > > > > const SQL = "Y-m-d H:i:s"; > > > const SQL_DATE = "Y-m-d"; > > > const SQL_TIME = "H:i:s"; > > > const SECOND = 1; > > > const MINUTE = 60; > > Not every minute has 60 seconds. > > > const HOUR = 3600; > > See above! > > > const DAY = 86400; > > Not every day has 86400 seconds. For one see the comment on MINUTE and > > also there are days that have more or less than 24 hours (DST) > > > > Therefore I wouldn't want to see those constants (that are also very > > easy to put up in userland - even though they aren't correct) in the > > PHP-Core. > > > > And as the SQL-Constants are also easily to implement in userland I'm > > not sure it makes to add them to the core… > > > > But that's just my 0.02€ > > > > Cheers > > > > Andreas > > > > > > -- > > ,,, > > (o o) > > +---------------------------------------------------------ooO-(_)-Ooo-+ > > | Andreas Heigl | > > | mailto:andr...@heigl.org N 50°22'59.5" E 08°23'58" | > > | http://andreas.heigl.org http://hei.gl/wiFKy7 | > > +---------------------------------------------------------------------+ > > | http://hei.gl/root-ca | > > +---------------------------------------------------------------------+ > > > > -- > Best regards, > Victor Bolshov >