Exemplo n.º 1
0
 def test_calendar_content(self):
     cal = self.project.calendars.values()[0]
     self.assertEqual(cal.name, "Calendrier Francais")
     self.assertEqual(cal.weekday, {
         'sat': 'non_working',
         'sun': 'non_working'
     })
     self.assertEqual(cal.national_days, [(1, 1), (5, 1), (5, 8), (7, 14),
                                          (8, 15), (11, 1), (11, 11),
                                          (12, 25)])
     self.assertEqual(cal.start_on, None)
     self.assertEqual(cal.stop_on, None)
     self.assertEqual(
         cal.day_types, {
             'working': [
                 u'Standard work day',
                 [(Time(8), Time(12)), (Time(13), Time(17, 24))]
             ],
             'non_working': [u'Week-end day', []],
             'holiday': [u'Day Off', []],
         })
     self.assertEqual(cal.default_day_type, 'working')
     dates = [("2002-12-31", "2002-12-26"), ("2003-03-14", "2003-03-10"),
              ("2003-08-18", "2003-08-14"), ("2004-05-21", "2004-05-20")]
     for (expected_end,
          expected_start), (start, end,
                            working) in zip(dates, cal.timeperiods):
         start = str(start).split()[0]
         end = str(end).split()[0]
         self.assertEqual(start, expected_start)
         self.assertEqual(end, expected_end)
         self.assertEqual(working, 'holiday')
 def test_iso_time(self):
     conv = SourceDataTypes.get_conversion('iso-time')
     self.assertEqual(conv('01:12:23.34'), Time(1, 12, 23.34))
     self.assertEqual(conv('1:12:23.4'), Time(1, 12, 23.4))
     self.assertEqual(conv('1:2:3.4'), Time(1, 2, 3.4))
     self.assertEqual(conv('01:02:03.4'), Time(1, 2, 3.4))
     self.assertEqual(conv(None), None)
     self.assertEqual(conv(''), None)
Exemplo n.º 3
0
    def test_mxDateTime():
        setupClass(DateTime2)
        _now = now()
        dt2 = DateTime2(col1=_now,
                        col2=_now.pydate(),
                        col3=Time(_now.hour, _now.minute, _now.second))

        assert isinstance(dt2.col1, col.DateTimeType)
        assert dt2.col1.year == _now.year
        assert dt2.col1.month == _now.month
        assert dt2.col1.day == _now.day
        assert dt2.col1.hour == _now.hour
        assert dt2.col1.minute == _now.minute
        assert dt2.col1.second == int(_now.second)

        assert isinstance(dt2.col2, col.DateTimeType)
        assert dt2.col2.year == _now.year
        assert dt2.col2.month == _now.month
        assert dt2.col2.day == _now.day
        assert dt2.col2.hour == 0
        assert dt2.col2.minute == 0
        assert dt2.col2.second == 0

        assert isinstance(dt2.col3, (col.DateTimeType, col.TimeType))
        assert dt2.col3.hour == _now.hour
        assert dt2.col3.minute == _now.minute
        assert dt2.col3.second == int(_now.second)
Exemplo n.º 4
0
    def test_mxDateTime():
        setupClass(DateTime2)
        _now = now()
        dt2 = DateTime2(col1=_now,
                        col2=_now,
                        col3=Time(_now.hour, _now.minute, int(_now.second)))

        assert isinstance(dt2.col1, col.DateTimeType)
        assert dt2.col1.year == _now.year
        assert dt2.col1.month == _now.month
        assert dt2.col1.day == _now.day
        assert dt2.col1.hour == _now.hour
        assert dt2.col1.minute == _now.minute
        assert dt2.col1.second == int(_now.second)

        assert isinstance(dt2.col2, col.DateTimeType)
        assert dt2.col2.year == _now.year
        assert dt2.col2.month == _now.month
        assert dt2.col2.day == _now.day
        if getConnection().dbName == "sqlite":
            assert dt2.col2.hour == _now.hour
            assert dt2.col2.minute == _now.minute
            assert dt2.col2.second == int(_now.second)
        else:
            assert dt2.col2.hour == 0
            assert dt2.col2.minute == 0
            assert dt2.col2.second == 0

        assert isinstance(dt2.col3, (col.DateTimeType, col.TimeType))
        assert dt2.col3.hour == _now.hour
        assert dt2.col3.minute == _now.minute
        assert dt2.col3.second == int(_now.second)
Exemplo n.º 5
0
 def __init__(self, locked=False):
     init_dict = self.__init_dict__
     for key in init_dict:
         value = init_dict[key]
         date, mo, da, ye, time, ho, mi, se = [None] * 8
         if type(value) in [str, unicode]:
             date, mo, da, ye, time, ho, mi, se = reDateTime.match(
                 value).groups()
         if type(init_dict[key]) == dict:
             setattr(self, key, makeFMData(
                 init_dict[key],
                 locked=False))  # lock all substructures??
         elif type(init_dict[key]) == list:
             l = []
             for d in init_dict[key]:
                 if type(d) == dict:
                     l.append(makeFMData(d))  # lock ??
                 else:
                     l.append(d)
             setattr(self, key, l)
         elif date and time:
             setattr(
                 self, key,
                 DateTime(int(ye), int(mo), int(da), int(ho), int(mi),
                          int(se)))
         elif date:
             setattr(self, key, Date(int(ye), int(mo), int(da)))
         elif time:
             setattr(self, key, Time(int(ho), int(mi), int(se)))
         else:
             setattr(self, key, init_dict[key])
     if locked:
         self.__modified__.add('__locked__')
Exemplo n.º 6
0
 def get_worktime(self, datetime):
     """
     return the number of seconds of availability on a given day
     """
     if not self.is_available(datetime):
         return Time(0)
     daytype = self.calendar.get_daytype(datetime)
     return self.calendar.get_worktime(daytype)
Exemplo n.º 7
0
 def test_parse_time_timezone(self):
     # Time zone information is ignored.
     expected = Time(13, 30, 29)
     self.assertEqual(expected, self.TIME("13:30:29+01", self.curs))
     self.assertEqual(expected, self.TIME("13:30:29-01", self.curs))
     self.assertEqual(expected, self.TIME("13:30:29+01:15", self.curs))
     self.assertEqual(expected, self.TIME("13:30:29-01:15", self.curs))
     self.assertEqual(expected, self.TIME("13:30:29+01:15:42", self.curs))
     self.assertEqual(expected, self.TIME("13:30:29-01:15:42", self.curs))
Exemplo n.º 8
0
 def setUp(self):
     """ called before each test from this class """
     _, _, resources, _, _, cal = simple_project()
     # set of dates
     self.date_last_week = DateTime(2004, 10, 1)
     self.date_today = DateTime(2004, 10, 7)
     self.date_tomorrow = DateTime(2004, 10, 8)
     self.date_next_week = DateTime(2004, 10, 13)
     self.date_next_score = DateTime(2004, 10, 26)
     # set up calendar
     cal.day_types = {'working':['Working', [(Time(8), Time(12)),
                                                 (Time(13), Time(17))]],
                          'halfday':['HalfDay', [(Time(9), Time(15))]],
                          'nonworking': ['Nonworking', []],
                          }
     cal.default_day_type = 'working'
     cal.add_timeperiod(self.date_last_week, self.date_last_week,
                           'nonworking')
     cal.add_timeperiod(self.date_today, self.date_today, 'working')
     cal.add_timeperiod(self.date_tomorrow, self.date_next_week, 'halfday')
     cal.weekday['sat'] = 'nonworking'
     cal.weekday['sun'] = 'nonworking'
     # set up calendar 2
     cal_2 = Calendar('c_2', 'Special Calendar')
     cal_2.add_timeperiod(self.date_next_week, self.date_next_score,
                            'nonworking')
     # build tree
     cal.append(cal_2)
     # set up resources
     self.r1 = resources[0] # tata
     self.r2 = resources[1] # toto
     self.r2.calendar = cal_2
Exemplo n.º 9
0
 def test_type_roundtrip_time_array(self):
     self._test_type_roundtrip_array(Time(10, 20, 30))
Exemplo n.º 10
0
 def test_type_roundtrip_time(self):
     self._test_type_roundtrip(Time(10, 20, 30))
Exemplo n.º 11
0
def TimeFromTicks(ticks):
    """Convert UNIX ticks into a mx.DateTime.Time."""
    return Time(*localtime(ticks)[3:6])
Exemplo n.º 12
0
 def test_iso_time_leap_seconds(self):
     """Err, shouldn't some of these throw errors, even allowing for leap seconds?"""
     conv = SourceDataTypes.get_conversion('iso-time')
     self.assertEqual(conv('01:02:60.4'), Time(1, 2, 60.4))
     self.assertEqual(conv('01:02:61.4'), Time(1, 2, 61.4))
     self.assertEqual(conv('01:02:62.4'), Time(1, 2, 62.4))
Exemplo n.º 13
0
 def test_time(self):
     data = [Time(0,0), 
             Time(23,59,59), 
             Time(12,0,0),
             None]
     self._test_array(soomarray.ArrayTime, data)
Exemplo n.º 14
0
"""
Projman - (c)2000-2010 LOGILAB <*****@*****.**> - All rights reserved.

Home: http://www.logilab.org/projman

Manipulate a xml project description.

This code is released under the GNU Public Licence v2. See www.gnu.org.
"""

from mx.DateTime import DateTime, Time, Date
from logilab.common import testlib
from projman.lib import Project, Calendar, Resource

MORNING = (Time(8), Time(12))
AFTERNOON = (Time(13), Time(17))
HALFDAY = (Time(9), Time(15))

def mk_calendar1():
    cal = Calendar('c_1', 'Calendrier 1')
    cal.day_types = {'nonworking': ['Non working', []],
                     'working':    ['Working', [MORNING, AFTERNOON]],

                         'halfday':    ['HalfDay', [HALFDAY]],
                         }
    cal.default_day_type = 'working'
    cal.national_days = [(1,1), (12,25), (11,11)]
    cal.start_on = DateTime(2004,01,06)
    cal.stop_on = DateTime(2006,12,29)
    cal.weekday['mon'] = 'working'
    cal.weekday['tue'] = 'working'
Exemplo n.º 15
0
 def test_adapt_time(self):
     from mx.DateTime import Time
     value = self.execute('select (%s)::time::text', [Time(13, 30, 29)])
     self.assertEqual(value, '13:30:29')
Exemplo n.º 16
0
 def test_type_roundtrip_time_array(self):
     from mx.DateTime import Time
     self._test_type_roundtrip_array(Time(10, 20, 30))
Exemplo n.º 17
0
 def test_time_optional_seconds(self):
     conv = SourceDataTypes.get_format('time', 'HH:MM')
     self.assertEqual(conv('12:23'), Time(12, 23))
     self.assertEqual(conv('12:23'), Time(12, 23, 0.0))