For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Issue with date2num

  • Hi,

    I use timezones intensively, and I had an issue with date2num on line 209 of utils/
    The code refers to an undefined variable dwhen:

    def date2num(dt, tz=None):
        Convert :mod:`datetime` to the Gregorian date as UTC float days,
        preserving hours, minutes, seconds and microseconds.  Return value
        is a :func:`float`.
        if tz is not None:
            dt = tz.localize(dwhen)
        if hasattr(dt, 'tzinfo') and dt.tzinfo is not None:
            delta = dt.tzinfo.utcoffset(dt)
            if delta is not None:
                dt -= delta
        base = float(dt.toordinal())
        if hasattr(dt, 'hour'):
            # base += (dt.hour / HOURS_PER_DAY +
            #          dt.minute / MINUTES_PER_DAY +
            #          dt.second / SECONDS_PER_DAY +
            #          dt.microsecond / MUSECONDS_PER_DAY
            #         )
            base = math.fsum(
                (base, dt.hour / HOURS_PER_DAY, dt.minute / MINUTES_PER_DAY,
                 dt.second / SECONDS_PER_DAY, dt.microsecond / MUSECONDS_PER_DAY))
        return base

    My guess is that dwhen must be substituted with dt.


  • administrators

    Can you show how you use the timezones? Thanks

  • On timers with tzdata parameters to trigger timers on market place's timezone.
    Our historicals datas are stored into a MongoDB through Arctic library, since ticks and bars are stored UTC, when building a feed I add tz parameter to point to the proper timezone.

    I guess that those uses of timezones pinpointed me to this issue.