TimeSpan

What about weeks? Shouldn’t the TimSpan be able to deliver the number of weeks?

Code:
import wx

dt1 = wx.DateTime()
dt2 = wx.DateTime()
dt1.Set(1, 0, 0, 0, 0, 0, 0)

year2 = 120000
print “Expected weeks:”, year2 * 52

for i in range(10):
dt2.Set(1, 0, year2, 0, 0, 0, 0)
diff = dt2 - dt1
print “Weks:”, diff.GetWeeks()
year2 += 1

Output:
Expected weeks: 6240000
Weks: -130020
Weks: -129968
Weks: -129915
Weks: -129863
Weks: -129811
Weks: -129759
Weks: -129707
Weks: -129655
Weks: -129602
Weks: -129550

···

Regards

Roger Lindberg

I'd just use python's datetime module instead. It may be easier.

-Chris

···

On Fri, Apr 12, 2013 at 12:41 AM, Roger Lindberg <borogerlindberg@gmail.com> wrote:

What about weeks? Shouldn't the TimSpan be able to deliver the number of
weeks?

Code:
import wx

dt1 = wx.DateTime()
dt2 = wx.DateTime()
dt1.Set(1, 0, 0, 0, 0, 0, 0)

year2 = 120000
print "Expected weeks:", year2 * 52

for i in range(10):
    dt2.Set(1, 0, year2, 0, 0, 0, 0)
    diff = dt2 - dt1
    print "Weks:", diff.GetWeeks()
    year2 += 1

Output:
Expected weeks: 6240000
Weks: -130020
Weks: -129968
Weks: -129915
Weks: -129863
Weks: -129811
Weks: -129759
Weks: -129707
Weks: -129655
Weks: -129602
Weks: -129550

Regards
Roger Lindberg

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Roger Lindberg wrote:

What about weeks? Shouldn't the TimSpan be able to deliver the number
of weeks?

A little experimentation shows that Milliseconds works fine up through
about 49 days. The other items (Hours, Days, Weeks) work fine up
through 4096 years. After that, they all go bonkers. I'm not sure I
understand why. The underlying C++ code stores the interval in
milliseconds, and 4096 years is only 44 bits worth of milliseconds.
Even if it were being stored in the Windows standard 100-nanosecond
units, it would still only be 61 bits.

Chris is right. When wx duplicates the facilities available in standard
Python, you should always use the standard Python methods. Use datetime
instead.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.