John,

I would prefer to be able to use the power and flexibility of datestr2num
and the underlying dateutil.parser, rather than writing my own parser.
However, looking further at dateutil.parser.parse, it takes an argument
tzinfos, which allows timezone names other than the local timezone and
UTC/GMT/Z to be understood within parse. I haven't worked out the full range
of functionality for the tzinfos argument, but a simple example would be:

> tzlibrary = {'EST':-5*60*60,'EDT':-4*60*60,'EST':-6*60*60,
> 'CDT':-5*60*60,'PST':-8*60*60,'PDT':-7*60*60}
> matplotlib.dates.date2num(dateutil.parser.parse('jan 1, 2007 12:00
> PST',tzinfos=tzlibrary))
732677.83333333337
> matplotlib.dates.date2num(dateutil.parser.parse('jan 1, 2007 12:00
> PDT',tzinfos=tzlibrary))
732677.79166666663
> matplotlib.dates.date2num(dateutil.parser.parse('jan 1, 2007 12:00
> EDT',tzinfos=tzlibrary))
732677.66666666663 

Actually, I can just duplicate datestr2num, but pass a tzinfos dictionary as
well, e.g.:

def datestr2num(d,tzinfos=None):
    """
    Convert a date string to a datenum using dateutil.parser.parse
    d can be a single string or a sequence of strings
    """
    if is_string_like(d):
        dt = dateutil.parser.parse(d,tzinfos=tzinfos)
        return date2num(dt)
    else:
        return date2num([dateutil.parser.parse(s,tzinfos=tzinfos) for s in
d])

explicitly passing a tzinfos of None does not cause any problems for
dateutil.parser.parse.

thanks,

Charles


John Hunter-4 wrote:
> 
> On 10/11/07, Charles Seaton <[EMAIL PROTECTED]> wrote:
> 
>> Any suggestions on how to get either matplotlib.dates.datestr2num or
>> dateutil.parser.parse to properly handle timezone information in the
>> datestring would be greatly appreciated.
> 
> Not sure how to answer this question vis-a-vid dateutil.parser, but
> you may want to consider creating your own datestr -> datetime
> converter using time.strptime and then allowing mpl to convert to
> numbers using date2num.  I think you can use the %Z format code for
> timezones.
> 
> JDH
> 
> 

-- 
View this message in context: 
http://www.nabble.com/datestr2num%2C-dateutil.parse-and-timezone-problems-tf4609462.html#a13167297
Sent from the matplotlib - users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to