Add Time class
Since you've already added a Date class without time components, would it make sense to include a Time class without date components (or fixed to 0000-01-01) with included Timezone support?
A Time with a timezone might be pretty confusing. How would you represent day rollovers? For example 2pm EST converted to JST?
What kind of methods would you envision being on a class like this?
Yeah, timezone wouldn't make sense for calculation especially since the date is critical. I was envisioning the standard methods but with restrictions to remove the date components - like the Date class does with time.
We might be able to implement DateTimeInterface but I'm not sure all the mutation methods that DateTime and Chronos offer would make sense.
Are there any needs in the cake framework for a time class?
It could be useful when mapping time columns. We currently map those to Cake\I18n\FrozenTime subclasses so maintaining backwards compatibility might be tricky unless we implement the very wide ChronosInterface.
One use case I have for a Time class is things like the duration of media. One of my side projects is a video on demand site, and it’s a real pain to constantly juggle DateTime instances, or work with total seconds. So if a Time class is introduced, I’ll ditch Carbon in a heartbeat!
@martinbean That sounds like an interesting scenario. I'm not sure it fits along the DateTimeInterface though, which leads me believe we want something else.
Time of day (point in time) and duration of media (length) are two different things.
@vlakoff Agreed. PHP provides DateInterval which can be used to define duration/interval lengths. Its API is not very elegant for dealing with media duration though.
There's CarbonInterval. So anyone interested could add similar class in Chronos based on that.
Any thoughts on interoparabiity with Carbon, @kylekatarnls?
Hi @ravage84! Thanks for the ping on this. Be aware Carbon evolved a lot since the Chronos apparition. Among other it can output duration, dates and relative times in 281 different languages and parse translated strings. It has tools for timezones (a dedicated CarbonTimeZone class), intervals and periods.
You could also take a look at business-time, a mixin for Carbon that provide Time and TimeRange classes from https://github.com/spatie/opening-hours/tree/master/src (hours and minutes only)
I maintain the 3 carbon, business-time, opening-hours
I already provided customizations to allow a fork project to converge. If CakePHP team wish to work on interoparabiity with Carbon, I would be glad to help.
I also dont like that marshaling a time value of H:i:s it becomes a string with datetime
11/3/2020 11:15AM
etc If you directly echo the string, you have weird results. It always needs then special treatment of the value
if ($field === 'time' && $resultValue) {
$resultValue = substr($resultValue, strpos($resultValue, ' ') + 1);
}
Do we have a plan of attack on this yet? For 4.2 maybe?
IMO this should be closed. The original request was introduced six years ago without an implementation, and the last activity was two years ago. Anyone could have taken a pass at this.
It's also not a clear parallel. Date is a desirable class because HMS are building blocks of a date (like ones, tens, hundreds are of thousands) and a Date cannot exist without those specs. Time (conceptually) exists as HMS apart from the date. I know PHP's native DateTime doesn't have support for either (hence Date here) but my point stands that there's clearly more need for the one than the other.