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;
const HOUR = 3600;
const DAY = 86400;
Easy-to-make feature that will be useful to a lot of PHP devs, I believe.
The exact naming of SQL_* constants is subject to dsicuss.
Best regards,
Victor
Best regards,
Victor Bolshov
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:andreas@heigl.org N 50°22'59.5" E 08°23'58" |
| http://andreas.heigl.org http://hei.gl/wiFKy7 |
+---------------------------------------------------------------------+
| http://hei.gl/root-ca |
+---------------------------------------------------------------------+
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:
- 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. - 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
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:andreas@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
Am 02.03.17 um 16:46 schrieb Crocodile:
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:
- 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.
IMO they then should be part of the caching (or whatever)-implementation
and not of DateTime. As when they are part of DateTime they will be
used in a DateTime-context where they shouldn't be used!
- 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.
When you need them use a Constant-Class or create a composer package
that contains your constants and require that.
That's much more extensible than having them in the core and needing to
maintain them for everyone…
But as I said: just my 0.02€
Cheers
Andreas
But of course, I don't see it as a must-have, just as nice-to-have.
Cheers,
VictorHi 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:andreas@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
--
,,,
(o o)
+---------------------------------------------------------ooO-(_)-Ooo-+
| Andreas Heigl |
| mailto:andreas@heigl.org N 50°22'59.5" E 08°23'58" |
| http://andreas.heigl.org http://hei.gl/wiFKy7 |
+---------------------------------------------------------------------+
| http://hei.gl/root-ca |
+---------------------------------------------------------------------+
Well, actually, that's a good reason for not having interval constants in
the core. Still think though that SQL formats would be a nice addition ;-)
Am 02.03.17 um 16:46 schrieb Crocodile:
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:
- 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.
IMO they then should be part of the caching (or whatever)-implementation
and not of DateTime. As when they are part of DateTime they will be
used in a DateTime-context where they shouldn't be used!
- 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.When you need them use a Constant-Class or create a composer package
that contains your constants and require that.That's much more extensible than having them in the core and needing to
maintain them for everyone…But as I said: just my 0.02€
Cheers
Andreas
But of course, I don't see it as a must-have, just as nice-to-have.
Cheers,
VictorHi 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:andreas@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--
,,,
(o o)
+---------------------------------------------------------ooO-(_)-Ooo-+
| Andreas Heigl |
| mailto:andreas@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
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 = 246060 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.
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:
- 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.- 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,
VictorHi 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:andreas@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