2
$\begingroup$

Suppose I have an EventSeries and I need to extract the values corresponding to some DateObject, taking properly into account the TimeZone and possible repetions of dates. I way I considered and probably used in the pas was to "evaluate" the EventSeries at the list of dates. Now I'm unable to reproduce this process.

For example consider the code:

date = DateObject[]
es = EventSeries[{1}, {{date}}]
es["DatePath"]
es["FirstDate"] === date
(*True*)

es[date]
(*Missing[]*)

I also tried

Replace[date, Rule @@@ es["DatePath"]]
(*no replacement done*)

with no success.

What is the supported way to do the job described?

Please note I have/want/need an EventSeries, not a potentially interpolating TimeSeries.

POSSIBLE WORKAROUND 1

First /@ Nearest[es["Times"] -> es["Values"], AbsoluteTime /@ {date, date, date}, {1, 0.01}]
$\endgroup$
0

1 Answer 1

3
$\begingroup$

I believe it may be a bug. DateObjects without a decimal seconds work as expected.

date2 = DateObject@{2008, 1, 1, 12, 1, 1}; 
es2 = EventSeries[{1}, {{date2}}]; 
es2[date2]
(* 1 *)

However, DateObjects with decimal seconds such as those returned by DateObject[] do not cooperate. I suggest reporting it to WRI.

As a workaround you can clean the fractional seconds from the dates before creating the EventSeries.

date3 = DateObject[];
date3 = date3 /. 
  DateObject[d_, TimeObject[t_, tr___], dr___] :> 
   DateObject[d, TimeObject[Round@t, tr], dr];
es3 = EventSeries[{1}, {{date3}}];
es3[date3]
(* 1 *)

Hope this helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.