Skip to content

Commit 955ef71

Browse files
author
Richard Jones
committed
fix Date.local()
1 parent 8be7af3 commit 955ef71

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

roundup/date.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: date.py,v 1.36 2002-10-12 23:10:36 richard Exp $
18+
# $Id: date.py,v 1.37 2002-12-09 02:43:21 richard Exp $
1919

2020
__doc__ = """
2121
Date, time and time interval handling.
@@ -273,11 +273,10 @@ def __repr__(self):
273273
return '<Date %s>'%self.__str__()
274274

275275
def local(self, offset):
276-
"""Return this date as yyyy-mm-dd.hh:mm:ss in a local time zone."""
277-
t = (self.year, self.month, self.day, self.hour + offset, self.minute,
278-
self.second, 0, 0, 0)
279-
self.year, self.month, self.day, self.hour, self.minute, \
280-
self.second, x, x, x = time.gmtime(calendar.timegm(t))
276+
""" Return this date as yyyy-mm-dd.hh:mm:ss in a local time zone.
277+
"""
278+
return Date((self.year, self.month, self.day, self.hour + offset,
279+
self.minute, self.second, 0, 0, 0))
281280

282281
def get_tuple(self):
283282
return (self.year, self.month, self.day, self.hour, self.minute,

test/test_dates.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: test_dates.py,v 1.14 2002-10-11 01:25:40 richard Exp $
18+
# $Id: test_dates.py,v 1.15 2002-12-09 02:43:21 richard Exp $
1919

2020
import unittest, time
2121

@@ -138,6 +138,11 @@ def testOffset(self):
138138
date = Date('2001-03-01.00:00:00') - Interval('00:00:3661')
139139
ae(str(date), '2001-02-28.22:58:59')
140140

141+
# local()
142+
date = Date("02:42:20")
143+
date = date.local(10)
144+
ae(str(date), '%s-%02d-%02d.12:42:20'%(y, m, d))
145+
141146
def testInterval(self):
142147
ae = self.assertEqual
143148
ae(str(Interval('3y')), '+ 3y')

0 commit comments

Comments
 (0)