# 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]


# 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];
ts["Dates"]


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?

• It may be difficult to turn this off. What problem does this behavior cause? Perhaps those are easier to solve. – MarcoB Jun 7 '16 at 23:24
• @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 Jun 8 '16 at 12:55
• You could consider writing a custom equality test based on DateDifference[] if need be. – J. M.'s ennui Jun 9 '16 at 21:12
• – alancalvitti Jul 28 '16 at 22:35

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]


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

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

ts["Dates"]
cleanDates@ts["Dates"]


• 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 Jun 9 '16 at 20:36
• @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 Jun 9 '16 at 20:42