How to prevent TimeSeries adding TimeObject parameter and TimeZone option to DateObjects?


TimeSeries adds a TimeObject parameter and a TimeZone option to DateObjects. How can this be prevented?

DateObjects are created without either of TimeObject or TimeZone.

dat = {DateObject@{2007, 1, #}, #} & /@ Range[2]

enter image description here

Version 11

Things were slightly improved in version 11. The "Dates" property now has the dates without the polluted TimeObject.

ts = TimeSeries[dat];
ts["Dates"] // InputForm

(* {DateObject[{2007, 1, 1}], DateObject[{2007, 1, 2}]} *)

However, the "FirstDate" and "LastDate" properties still have the TimeObject pollution.

ts /@ {"FirstDate", "LastDate"} // InputForm

(* {DateObject[{2007, 1, 1}, TimeObject[{0, 0, 0.}, TimeZone -> -3.], TimeZone -> -3.],
    DateObject[{2007, 1, 2}, TimeObject[{0, 0, 0.}, TimeZone -> -3.], TimeZone -> -3.] } *)

My fingers are crossed for 11.1

Version 10.4.1

When loaded into a TimeSeries DateObjects are polluted with these addtions.

ts = TimeSeries[dat];

enter image description here

The extras can be see from InputForm.

ts["FirstDate"] // InputForm
(* DateObject[{2007, 1, 1}, TimeObject[{0, 0, 0.}, TimeZone -> -3.], TimeZone -> -3.] *)

How can this be turned off?


Posted 2016-06-07T19:20:51.120

Reputation: 35 657

It may be difficult to turn this off. What problem does this behavior cause? Perhaps those are easier to solve. – MarcoB – 2016-06-07T23:24:38.310

@MarcoB The issue is comparison with dates in the code. All dates in the code do not have the extra bits in them. So wherever I compare dates with the polluted TimeSeries dates I do not get equality. – Edmund – 2016-06-08T12:55:05.487

You could consider writing a custom equality test based on DateDifference[] if need be. – J. M.'s ennui – 2016-06-09T21:12:41.940



I could not find a way to prevent the addition, so you might be left with cleaning up after the fact.

Depending on which side you control, you could either add the missing bits, or remove the excess.

If you want to add the missing parts:

datComplete = {DateObject[{2007, 1, #}, TimeObject[{0, 0, 0}], 
                  TimeZone -> $TimeZone], #} & /@ Range[2]

complete dates

Alternatively, if you want to clean up the output of TimeSeries:

cleanDates[date_DateObject] :=
    DateObject[{y_, m_, d_}, ___] :> DateObject[{y, m, d}]
SetAttributes[cleanDates, Listable]


the original cleaned up


Posted 2016-06-07T19:20:51.120

Reputation: 53 573

Yes. I capitulated to the cleaning scenario shortly after posting as work needed to continue. (1+) I don't get why WRI is added things it. It is very annoying to slap all that bloat into your data with no way of preventing it. An odd choice. – Edmund – 2016-06-09T20:36:59.787

@Edmund It certainly is! My best guess is that it has to do with the fact that interpolation will be used to fill in missing values, but still... More importantly, I'm unpleasantly surprised that the comparison fails! I'd expect that, when a comparison is called for, the missing parts in your simpler DateObjects would be filled in with appropriate default values, just like TimeSeries does! That's the unsettling bit, in my opinion. I'd otherwise be OK with the added bits, if the comparison to a simpler structure still worked automagically... – MarcoB – 2016-06-09T20:42:24.717