chronos icon indicating copy to clipboard operation
chronos copied to clipboard

Add Time class

Open psaintjust opened this issue 9 years ago • 14 comments

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?

psaintjust avatar Jul 22 '16 14:07 psaintjust

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?

markstory avatar Jul 22 '16 16:07 markstory

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.

psaintjust avatar Jul 22 '16 17:07 psaintjust

We might be able to implement DateTimeInterface but I'm not sure all the mutation methods that DateTime and Chronos offer would make sense.

markstory avatar Jul 22 '16 21:07 markstory

Are there any needs in the cake framework for a time class?

psaintjust avatar Jul 23 '16 11:07 psaintjust

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.

markstory avatar Jul 23 '16 13:07 markstory

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 avatar Aug 16 '16 15:08 martinbean

@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.

markstory avatar Aug 16 '16 17:08 markstory

Time of day (point in time) and duration of media (length) are two different things.

vlakoff avatar Oct 09 '16 21:10 vlakoff

@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.

markstory avatar Oct 10 '16 00:10 markstory

There's CarbonInterval. So anyone interested could add similar class in Chronos based on that.

ADmad avatar Jul 25 '19 12:07 ADmad

Any thoughts on interoparabiity with Carbon, @kylekatarnls?

ravage84 avatar Jul 31 '19 23:07 ravage84

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.

kylekatarnls avatar Aug 01 '19 10:08 kylekatarnls

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?

dereuromark avatar Nov 13 '20 12:11 dereuromark

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.

MGatner avatar Sep 05 '22 16:09 MGatner