Semantics of time tuples?

13 views
Skip to first unread message

felciano

unread,
Jun 3, 2008, 3:34:12 PM6/3/08
to parsedatetime-dev
Hi -

Great library -- thank you for making it available! I'm trying to get
up to speed with it and can't find the documentation that describes
the structure of the tuple returned by parse(). It also doesn't seem
to be described on the examples page (http://code.google.com/p/
parsedatetime/wiki/Examples). Any pointers would be appreciated...

Thanks!

Ramon

bear

unread,
Jun 3, 2008, 5:36:06 PM6/3/08
to parsedat...@googlegroups.com
Thanks :)

The return from parse() is a tuple that is the value parsed (or the
source time if not parsed) and a flag value.

0 = not parsed at all
1 = parsed as a date
2 = parsed as a time
3 = parsed as a datetime

parse() = (parsedvalue, flag)

hope this helps!

--
---
Bear

be...@seesmic.com (work)
be...@code-bear.com (jabber & email)
http://code-bear.com/bearlog (weblog)

PGP Fingerprint = 9996 719F 973D B11B E111 D770 9331 E822 40B3 CD29

felciano

unread,
Jun 3, 2008, 8:52:11 PM6/3/08
to parsedatetime-dev
Maybe I'm being an idea, but what is "value parsed"? More
specifically, in the following example, what does the mystery variable
get bound to?

result = p.parse("next friday")
print result
((year, month, day, hour, minute, second, microsecond, tzinfo,
mystery), flag) = result
print year

From the python docs, a datetime tuple seems to be defined as:

class datetime(year, month, day[, hour[, minute[, second[,
microsecond[, tzinfo]]]]])

That's an 8-tuple, yet you return a 9-tuple :-)

Ramon

On Jun 3, 2:36 pm, bear <bea...@gmail.com> wrote:
> Thanks :)
>
> The return from parse() is a tuple that is the value parsed (or the
> source time if not parsed) and a flag value.
>
> 0 = not parsed at all
> 1 = parsed as a date
> 2 = parsed as a time
> 3 = parsed as a datetime
>
> parse() = (parsedvalue, flag)
>
> hope this helps!
>
> On Tue, Jun 3, 2008 at 3:34 PM, felciano <felci...@gmail.com> wrote:
>
> > Hi -
>
> > Great library -- thank you for making it available! I'm trying to get
> > up to speed with it and can't find the documentation that describes
> > the structure of the tuple returned by parse(). It also doesn't seem
> > to be described on the examples page (http://code.google.com/p/
> > parsedatetime/wiki/Examples). Any pointers would be appreciated...
>
> > Thanks!
>
> > Ramon
>
> --
> ---
> Bear
>
> b...@seesmic.com (work)
> b...@code-bear.com (jabber & email)http://code-bear.com/bearlog(weblog)

bear

unread,
Jun 3, 2008, 10:57:22 PM6/3/08
to parsedat...@googlegroups.com
a tuple in python is just a list that cannot be modified - so it can
be 1, 2, 3 or as many items as required.

The first value of the two value tuple we return is the datetime item
that the pdt library was able to parse. The second value is a flag to
let you know what kind of value is found in the first item.

--
---
Bear

PGP Fingerprint = 9996 719F 973D B11B E111 D770 9331 E822 40B3 CD29

felciano

unread,
Jun 19, 2008, 2:44:55 PM6/19/08
to parsedatetime-dev
Hi --

Sorry to not have been clearer about this. Here is the tuple in
question:

((year, month, day, hour, minute, second, microsecond, tzinfo,
mystery), flag) = result

> The second value is a flag to
> let you know what kind of value is found in the first item.
>
This is the variable "flag" above.

> The first value of the two value tuple we return is the datetime item
> that the pdt library was able to parse.
>
In the above example, this is a tuple with 9 values. From my reading
of the Python docs (http://docs.python.org/lib/datetime-
datetime.html), a standard datetime object only has 8 items. So it
appears that pdt is returning an extra 9th value in the tuple, which
I've labeled "mystery" above. What does it refer to?

Thx,

Ramon

bear

unread,
Jun 23, 2008, 1:27:02 AM6/23/08
to parsedat...@googlegroups.com
PDT returns the stock time module tuple:

lib/module-time.html:

0 tm_year (for example, 1993)
1 tm_mon range [1,12]
2 tm_mday range [1,31]
3 tm_hour range [0,23]
4 tm_min range [0,59]
5 tm_sec range [0,61]; see (1) in strftime() description
6 tm_wday range [0,6], Monday is 0
7 tm_yday range [1,366]
8 tm_isdst 0, 1 or -1; see below

--

Reply all
Reply to author
Forward
0 new messages