haskell-chart icon indicating copy to clipboard operation
haskell-chart copied to clipboard

make `UTCTime` an instance of `PlotValue`

Open cheecheeo opened this issue 11 years ago • 4 comments

UTCTime from the time library supports addUTCTime and diffUTCTime making it the preferred type for time manipulations. It would be awesome if chart could support UTCTime as a PlotValue.

cheecheeo avatar Sep 03 '14 23:09 cheecheeo

Is the behaviour for LocalTime adequate for UTCTime? ie, is an instance of PlotValue expressed in terms of LocalTime all you need:

instance PlotValue UTCTime where
    toValue    = doubleFromLocalTime . utcToLocalTime
    fromValue  = localTimeToUtc . localTimeFromDouble
    autoAxis   = autoTimeAxis . map utcToLocalTime

timbod7 avatar Sep 06 '14 04:09 timbod7

I think you'd need to change utcToLocalTime to utcToLocalTime utc but yes, that's what I'm looking for (though, I am not a time expert). localTimeToUTC also needs a TimeZone so maybe fromValue would need a better definition.

cheecheeo avatar Sep 06 '14 17:09 cheecheeo

It turns out that I was wrong - the above approach is not enough, as autoTimeAxis has type AxisFn LocalTime. Some of the logic inside Graphics.Rendering.Chart.Axis.LocalTime would need to be abstracted to work for both UTCTime and LocalTime.

Please send a patch if this is important for you. As a workaround, you can just convert you UTCTime values to LocalTime values before plotting them.

timbod7 avatar Sep 08 '14 04:09 timbod7

Will be solved in #154

phadej avatar Apr 15 '17 09:04 phadej