[issue1673409] datetime module missing some important methods

2010-04-21 Thread Alexander Belopolsky

Alexander Belopolsky alexander.belopol...@gmail.com added the comment:

With issue2706 accepted, I think this issue can now be rejected because 
proposed td.tosecs() can now be spelled simply as td/timedelta(seconds=1).

The other RFE for a totimestamp() method is a duplicate of issue2736.

--
nosy: +Alexander.Belopolsky, mark.dickinson -belopolsky

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2010-04-21 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Closing this as a duplicate of issue 2736, as suggested.  I'll combine the nosy 
lists.

(BTW, as well as the newly introduced division methods, td.tosecs already 
exists, except that it's spelt td.total_seconds.)

--
resolution:  - duplicate
status: open - closed
superseder:  - datetime needs an epoch method

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2010-04-21 Thread Alexander Belopolsky

Alexander Belopolsky alexander.belopol...@gmail.com added the comment:

On Wed, Apr 21, 2010 at 2:03 PM, Mark Dickinson rep...@bugs.python.org wrote:
..
 (BTW, as well as the newly introduced division methods, td.tosecs already 
 exists, except that it's spelt td.total_seconds.)

Aggrrr!  How did that slip in? :-)

8639913600.0

Shouldn't td.total_seconds() return Decimal?  Maybe in py4k ...

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2010-04-21 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

 Aggrrr!  How did that slip in? :-)

Blame Antoine.  :)  (See issue 5788 and revision 76529.)

 Shouldn't td.total_seconds() return Decimal?  Maybe in py4k ...

Yes, that would have been nice.

I'm not sure that the Decimal type is well-established enough yet that it's 
okay to return Decimal instances from random unrelated modules, though.  Maybe 
someday.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-12-16 Thread Marc-Andre Lemburg

Changes by Marc-Andre Lemburg m...@egenix.com:


--
nosy:  -lemburg

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-12-15 Thread Sebastian Rittau

Sebastian Rittau srit...@jroger.in-berlin.de added the comment:

A timedelta.toseconds method (or equivalent) makes no sense. The number
of seconds in a day is not fixed (due to leap seconds) and relying on
such a method would introduce subtle bugs. The only way to find out the
number of seconds in a range of dates is if you have a concrete date range.

--
nosy: +srittau

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-12-15 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@haypocalc.com:


Removed file: http://bugs.python.org/file11919/timedelta_toseconds_float.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-12-15 Thread Jon Ribbens

Jon Ribbens jribb...@users.sourceforge.net added the comment:

 A timedelta.toseconds method (or equivalent) makes no sense.
 The number of seconds in a day is not fixed (due to leap seconds) and
 relying on such a method would introduce subtle bugs.

You are misunderstanding what timedelta is. It is a fixed-length period
of time. It is stored as a number of (24x3600-second) days, seconds and
microseconds. There is no start date or end date, so the concept of
leap seconds just does not apply.

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-12-15 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

 The number of seconds in a day is not fixed (due to leap seconds)

POSIX timestamp doesn't count leap seconds. It looks like the datetime 
module is not aware of the leap seconds:

 print datetime.datetime(2006, 1, 1) - datetime.datetime(2005, 12, 
31)
1 day, 0:00:00

About my method: I finally prefer datetime/datetime or 
datetime//datetime instead of a toseconds() method. And to convert a 
timestamp to a timestamp: see my patch attached to issue #2736.

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-12-15 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

I also think totimestamp() on datetime objects would be useful, I've
missed it myself a couple of times. The return value should be similar
to that of time.time(), i.e. a float.

--
nosy: +pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-12-15 Thread Sebastian Rittau

Sebastian Rittau srit...@jroger.in-berlin.de added the comment:

Leap second handling is usually configurable. Default on Debian Linux
(but similar on RHEL and SuSE):

 int(date(1994,1,1).strftime(%s)) - int(date(1993,1,1).strftime(%s))
31536000

After doing cp /usr/share/zoneinfo/right/Europe/Berlin /etc/localtime:

 int(date(1994,1,1).strftime(%s)) - int(date(1993,1,1).strftime(%s))
31536001

Also, NTP servers usually get this right. I don't think, Python should
promote a wrong date handling by default, even if it's convenient.

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-12-15 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

What you say is with 99500 days or more, the microsecond error is
bigger than 90%. It means that with epoch starting at 1970, you can
still return timestamps with a 1-2 microsecond accuracy for the year 2242.

Additional precision would be overkill.

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-12-15 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

I removed my .toseconds() method patch because I prefer division. 
See issue #2706 for divison, divmod, etc.

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-12-15 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

 (...) totimestamp() (...) return value should be similar
 to that of time.time(), i.e. a float

float is a source of many problems (rounding problems), especially for 
huge values: float is unable to store correctly microseconds for big 
values: see msg75426. A simple tuple (int, int) is simple and there is 
no rounding/float limit.

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-12-15 Thread Brett Cannon

Changes by Brett Cannon br...@python.org:


--
nosy:  -brett.cannon

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-11-14 Thread STINNER Victor

STINNER Victor [EMAIL PROTECTED] added the comment:

 (t - epoch) // timedelta(seconds=1)

I don't like this syntax, because I can't guess the result unit:
  datetime - datetime - timedelta
but:
  timedelta / timedelta - seconds? days? nanoseconds?

If you example, you used timedelta(seconds=1), but what is the result 
unit if you use timedelta(hours=1)? or timedelta(days=1, 
microseconds=1)?

The problem is that timedelta has no unit (or has multiple units), 
whereas timedelta.toseconds() are seconds. So about your example:

 (t - epoch).toseconds()
-- fractional seconds
 int((t - epoch).toseconds())
-- whole seconds

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-11-14 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc [EMAIL PROTECTED] added the comment:

 timedelta / timedelta - seconds? days? nanoseconds?

The quotient of two timedelta is a dimensionless number with no unit:
timedelta(hours=1) / timedelta(minutes=5) == 12.0
This seems well defined, where is the ambiguity?

--
nosy: +amaury.forgeotdarc

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-11-14 Thread Alexander Belopolsky

Alexander Belopolsky [EMAIL PROTECTED] added the comment:

I was going to say the same as Amaury: timedelta / timedelta is
dimensionless (time units cancel each other in division) and the
advantage of this notation is that you get a way to express
timedelta.toxxx for all units accepted in constructor and even toweeks
becomes simple d / timedelta(7).

I've started flashing out a patch and then recalled that I've seen one
at issue2706 .  So instead of attaching a new patch here, I am going
to review the one in issue2706 now.

There was also some related discussion at issue4291 .   Apparently it
has been suggested that timedelta to integer and float conversions
would be a better alternative to timedelta / timedelta division.   I
disagree.  Integer conversion is ambiguous - should it be to seconds,
to microseconds or to timedelta.resolution (whatever that will become
in the future)?  Floating point conversion may loose precision as Tim
pointed out in msg26266 .  That would lead users to scratching their
heads over what to use float(d1)/float(d2) or float(d1)/int(d2) or
even int(d1)/int(d2) with true division on.

This said, let's move this discussion to issue2706 now.

On Fri, Nov 14, 2008 at 7:17 AM, Amaury Forgeot d'Arc
[EMAIL PROTECTED] wrote:

 Amaury Forgeot d'Arc [EMAIL PROTECTED] added the comment:

 timedelta / timedelta - seconds? days? nanoseconds?

 The quotient of two timedelta is a dimensionless number with no unit:
timedelta(hours=1) / timedelta(minutes=5) == 12.0
 This seems well defined, where is the ambiguity?

 --
 nosy: +amaury.forgeotdarc

 ___
 Python tracker [EMAIL PROTECTED]
 http://bugs.python.org/issue1673409
 ___


___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-11-11 Thread Alexander Belopolsky

Alexander Belopolsky [EMAIL PROTECTED] added the comment:

Chris I keep needing to know the number of seconds that a timedelta
Chris represents.

I propose an alternative approach that I believe will neatly solve 
fractional vs. whole seconds and multitude of conceivable toxxx methods:

Let's extend timedelta's div and floordiv methods to allow 

 (t - epoch) // timedelta(seconds=1)
-- whole seconds

and  

 (t - epoch) / timedelta(seconds=1)
-- fractional seconds

--
nosy: +belopolsky

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-11-10 Thread STINNER Victor

STINNER Victor [EMAIL PROTECTED] added the comment:

See also issue2736

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-10-31 Thread Steve Roberts

Steve Roberts [EMAIL PROTECTED] added the comment:

I would like to add a use case, generating random dates. Especially
generating random dates/times according to different probability
distributions and within ranges. It would be nicest if operations could
be done directly with datetime, date, time and timedelta objects, but
easy conversion to and from timestamps as requested here would also make
for reasonably convenient code (i.e. get timestamp conversions from
objects to represent ranges, generate random numbers and convert back)

--
nosy: +steve.roberts

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-10-31 Thread Marc-Andre Lemburg

Marc-Andre Lemburg [EMAIL PROTECTED] added the comment:

You can have all this by using the time module's functions.

It is true that these don't work for all dates, but they are still
useful to have.

FWIW: mxDateTime has always had methods to convert the date/time values
to ticks and back again:

http://www.egenix.com/products/python/mxBase/mxDateTime/

Since most of the datetime module was inspired by mxDateTime, I wonder
why these were left out.

--
nosy: +lemburg

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-10-31 Thread Skip Montanaro

Skip Montanaro [EMAIL PROTECTED] added the comment:

Unassigning.  Haven't heard from Tim in quite awhile and he's made no 
input on this issue.  Also bump to 2.7.

--
assignee: tim_one - 
versions: +Python 2.7 -Python 2.6

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-10-31 Thread STINNER Victor

STINNER Victor [EMAIL PROTECTED] added the comment:

I wrote this function is my program:

def timedelta2seconds(delta):

Convert a datetime.timedelta() objet to a number of second
(floatting point number).

 timedelta2seconds(timedelta(seconds=2, microseconds=4))
2.04
 timedelta2seconds(timedelta(minutes=1, milliseconds=250))
60.25

return delta.microseconds / 100.0 \
+ delta.seconds + delta.days * 60*60*24

About the use cases: I use it to compute the compression rate of an 
audio song (bytes / seconds), to compute the bit rate of a video 
(bytes / seconds). I'm using datetime.timedelta() to store the 
audio/video duration.

It's not related to time_t: see issue #2736 for 
datetime.datetime.totimestamp(). And about time_t: I don't about 31 
bits signed integer. It's not beacuse other programs have arbitrary 
limits than Python should also be limited.

About the patch: I don't like the name tosecs, it's not consistent 
with the constructor: timedelta(seconds=...).tosec[ond]s(). And why 
dropping the microseconds? For short duration, microseconds are 
useful.

--
nosy: +haypo

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2008-07-10 Thread Erik Stephens

Erik Stephens [EMAIL PROTECTED] added the comment:

I'm not sure this is still being considered, so I just wanted to add my
opinion.  This seems like such a simple request being made overly
complicated.  We just want seconds since epoch since that is used in
many other functions and libraries (i.e. the time module,
os.stat().st_mtime).  Why is there toordinal()?!?  If there is going to
be any toxxx() methods, there should definitely be a
tosecs()/totimestamp() method or an 'epoch/timestamp' attribute.  For
boundary cases, I would look to the std time module for guidance.

--
nosy: +erik.stephens

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-12-01 Thread Chris AtLee

Chris AtLee added the comment:

timedelta.todays() could be useful in general I suppose.  I think
timedelta.toweeks() could be omitted since it's simple division by an
easy to recognize constant...also the timedelta docs say that it stores
data in terms of microseconds, seconds, and days.

OTOH tohours(), tominutes(), etc. (all the units that the constructor
uses) could be useful in some cases.

My feeling is that adding a method for each time unit bloats the API too
much.  Personally I've only ever wanted to know the number of seconds a
timedelta represents. It seems like seconds are a good base unit to
support since it allows easier interoperability with other python types
and external data.

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-11-30 Thread Skip Montanaro

Skip Montanaro added the comment:

Chris I keep needing to know the number of seconds that a timedelta
Chris represents, so I implemented the following patch.

I can sympathize, but if we accept this patch, for symmetry reasons
shouldn't we also add .todays, .tomicroseconds and maybe even .toweeks?

Skip

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-11-30 Thread Chris AtLee

Chris AtLee added the comment:

I keep needing to know the number of seconds that a timedelta represents,
so I implemented the following patch.

This returns only the integer portion, but could be modified to return a
floating point value.

--
nosy: +catlee
Added file: http://bugs.python.org/file8837/timedelta.diff

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_Index: Doc/library/datetime.rst
===
--- Doc/library/datetime.rst	(revision 59236)
+++ Doc/library/datetime.rst	(working copy)
@@ -266,7 +266,13 @@
 efficient pickling, and in Boolean contexts, a :class:`timedelta` object is
 considered to be true if and only if it isn't equal to ``timedelta(0)``.
 
+Instance methods:
 
+.. method:: timedelta.tosecs()
+
+   Returns the total number of seconds this timedelta object represents.
+   This is equivalent to (timedelta.days * 3600 * 24) + timedelta.seconds
+
 .. _datetime-date:
 
 :class:`date` Objects
Index: Lib/test/test_datetime.py
===
--- Lib/test/test_datetime.py	(revision 59236)
+++ Lib/test/test_datetime.py	(working copy)
@@ -475,6 +475,11 @@
 self.assertEqual(str(t3), str(t4))
 self.assertEqual(t4.as_hours(), -1)
 
+def test_tosecs(self):
+for s in (100, 1000, 1000, 1000):
+td = timedelta(seconds = s)
+self.assertEqual(td.tosecs(), s)
+
 #
 # date tests
 
Index: Modules/datetimemodule.c
===
--- Modules/datetimemodule.c	(revision 59236)
+++ Modules/datetimemodule.c	(working copy)
@@ -2058,6 +2058,28 @@
 	return Py_BuildValue(ON, Py_Type(self), delta_getstate(self));
 }
 
+static PyObject *
+delta_tosecs(PyDateTime_Delta* self)
+{
+PyObject*t1, *t2;
+PyObject*days, *secs;
+PyObject*retval;
+
+t1 = PyLong_FromLong(GET_TD_DAYS(self));
+t2 = PyLong_FromLong(3600*24);
+days = PyNumber_Multiply(t1, t2);
+Py_DECREF(t1);
+Py_DECREF(t2);
+
+secs = PyLong_FromLong(GET_TD_SECONDS(self));
+
+retval = PyNumber_Add(days, secs);
+Py_DECREF(days);
+Py_DECREF(secs);
+
+return retval;
+}
+
 #define OFFSET(field)  offsetof(PyDateTime_Delta, field)
 
 static PyMemberDef delta_members[] = {
@@ -2077,6 +2099,8 @@
 	{__reduce__, (PyCFunction)delta_reduce, METH_NOARGS,
 	 PyDoc_STR(__reduce__() - (cls, state))},
 
+{tosecs, (PyCFunction)delta_tosecs, METH_NOARGS,
+ PyDoc_STR(Total number of seconds represented by this timedelta object.)},
 	{NULL,	NULL},
 };
 
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-11-02 Thread Jon Ribbens

Jon Ribbens added the comment:

 No fractions of a second...

If we're expecting floating-point, then everything you said earlier
about the limitations of ints was a bit redundant ;-)

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-11-02 Thread Tom Lazar

Tom Lazar added the comment:

unless I'm missing something important this will do the trick quite 
nicely:

 from datetime import datetime
 datetime(2007, 12, 24, 20, 0).strftime(%s)
'1198522800'

For most imaginable use cases, where an epoch style time stamp is 
required this should be enough.

HTH,

Tom

--
nosy: +tomster

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-11-02 Thread Skip Montanaro

Skip Montanaro added the comment:

Tom unless I'm missing something important this will do the trick quite
Tom nicely:

 from datetime import datetime
 datetime(2007, 12, 24, 20, 0).strftime(%s)
Tom '1198522800'

Tom For most imaginable use cases, where an epoch style time stamp is
Tom required this should be enough.

No fractions of a second...

Skip

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-11-02 Thread Skip Montanaro

Skip Montanaro added the comment:

One other thing worth noting is that %s is not universally
available.  Solaris, for example, lacks it in its strftime()
implementation.  (It has a bazillion other non-standard
format strings but not %s.)

Skip

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-11-02 Thread Skip Montanaro

Skip Montanaro added the comment:

 No fractions of a second...

Jon If we're expecting floating-point, then everything you said earlier
Jon about the limitations of ints was a bit redundant ;-)

Yes, sorry.  I responded to the mail without going back and reviewing the
entire thread.  (It's been a couple months.)  Note however that my example
to_timestamp() function converts the microseconds field to seconds and
include them in the result.

So, are we concluding that nothing needs to be added to the datetime module?

Skip

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-11-02 Thread Jon Ribbens

Jon Ribbens added the comment:

Well, I still think that a convert-to-time_t function is essential, and
I don't buy any of the counter-arguments so far. The only argument I can
see is should it return float or integer? - floats are inaccurate and
integers can't represent partial seconds.

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-11-02 Thread Brett Cannon

Brett Cannon added the comment:

This is not going to go anywhere without someone offering a patch to
implement this.  Plus I suspect this has a much greater use in the C API
than in the Python API for datetime.

--
nosy: +brett.cannon

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-11-02 Thread Jon Ribbens

Jon Ribbens added the comment:

Skip has already provided what amounts to a patch. It just needs to be
decided whether to (a) not include it, (b) include it with the floating
point part, or (c) include it without the floating point part.

I couldn't comment as to how many people need it. I can say that I need
it, and anyone else who's used to manipulating dates and times either
in a unixy sort of way or with libraries that are expecting time_t's
will need it.

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-09-02 Thread Jon Ribbens

Jon Ribbens added the comment:

Almost everything you just said about time_t is wrong. time_t is signed,
and always has been (otherwise the 'end of time' for 32-bit time_t would
be 2106, not 2038). Also, time_t does not end at 2038 because nothing
says it must be 32 bits. Also, Python has 'long integers' which do not
overflow.

Also, I don't understand what you mean about use cases. The use case
is dealing with anything which expects standard Unix time_t, for
example the Python standard library. The use case I have personally is
the program I was working on when I encountered the problem described in
this bug report. Also I think symmetry is a darn good argument. Why does
fromtimestamp exist if, as you claim, nobody uses time_t?

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-09-02 Thread Skip Montanaro

Skip Montanaro added the comment:

Jon Almost everything you just said about time_t is wrong. time_t is
Jon signed, and always has been (otherwise the 'end of time' for 32-bit
Jon time_t would be 2106, not 2038). Also, time_t does not end at 2038
Jon because nothing says it must be 32 bits. Also, Python has 'long
Jon integers' which do not overflow.

My apologies about goofing up on the signedness of time_t.  What are you
going to do with a long integer that you can't do with a datetime object?
You clearly can't pass it directly to any Unix library functions which
expect time_t.  Converting it can overflow.

Jon Also, I don't understand what you mean about use cases. The use
Jon case is dealing with anything which expects standard Unix time_t,
Jon for example the Python standard library. The use case I have
Jon personally is the program I was working on when I encountered the
Jon problem described in this bug report. Also I think symmetry is a
Jon darn good argument. Why does fromtimestamp exist if, as you claim,
Jon nobody uses time_t?

What should datetime.datetime(, 1, 1).totimestamp() return?  How would
you pass it to something which accepts a time_t?  The fromtimestamp
functions work simply because the range of time_t is a proper subset of the
range of Python's datetime objects.  Symmetry gets you little.  In
situations where you need Unix timestamps and you know your datetime objects
are within the bounds representable by time_t, you can define a convenience
function:

def totimestamp(dt):
return time.mktime(dt.timetuple()) + dt.microsecond/1e6

This will, of course, fail if the year is too big or too small (and will
fail in platform-dependent ways if the underlying platform's range of
representable dates has different bounds than Unix does).  Doing it without
resorting to calling time.mktime is also nontrivial.  Under the covers the
datetime module currently uses platform functions to get time information
anyway.  It doesn't do a lot of low-level time arithmethic itself.
Implementing fromtimestamp would require a fair amount of effort unless you
were willing to punt and just raise OverflowError for dates outside the
system's range.

Skip

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1673409] datetime module missing some important methods

2007-09-01 Thread Skip Montanaro

Skip Montanaro added the comment:

There is no datetime.totimestamp because the range
of time represented by a datetime object far
exceeds the range of a normal int-based Unix
timestamp (roughly 1970-2038).  Datetime objects
before the start of the Unix epoch would be
represented by negative numbers.  As far as I
know, the common Unix library functions which
accept epoch times wouldn't know what to do
with a negative number.

That said, you stated these missing methods
were important.  Can you offer some use
cases which would support that contention?
I personally don't think a argument for
symmetry would be a convincing use case and
that's the only one I can think of.

--
nosy: +skip.montanaro

_
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1673409
_
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com