Example #1
0
def a_time_period():
    """Create a random :doc:`TimePeriod <timelinelib_canvas_data_timeperiod>` object."""
    year = random.randint(1, 4000)
    month = random.randint(1, 12)
    day = random.randint(1, 28)
    end_year = year + random.randint(1, 5)
    end_month = random.randint(1, 12)
    end_day = random.randint(1, 28)
    return TimePeriod(
        CopticDateTime(year, month, day, 0, 0, 0).to_time(),
        CopticDateTime(end_year, end_month, end_day, 0, 0, 0).to_time())
Example #2
0
 def get_value(self):
     if self.time_picker.IsShown():
         hour, minute, second = self.time_picker.GetCopticTime()
     else:
         hour, minute, second = (0, 0, 0)
     year, month, day = self.date_picker.GetCopticDate()
     return CopticDateTime(year, month, day, hour, minute, second).to_time()
Example #3
0
 def now(self):
     py = datetime.now()
     julian_day = gregorian_ymd_to_julian_day(py.year, py.month, py.day)
     year, month, day = julian_day_to_coptic_ymd(julian_day)
     coptic = CopticDateTime(year, month, day, py.hour, py.minute,
                             py.second)
     return coptic.to_time()
Example #4
0
def human_time_to_coptic(human_time):
    """
    Create a :doc:`CopticTime <timelinelib.calendar.coptic.time>` object
    from a human readable date and time string.
    """
    (year, month, day, hour, minute, seconds) = human_time_to_ymdhm(human_time)
    return CopticDateTime(year, month, day, hour, minute, seconds).to_time()
Example #5
0
 def parse_time(self, time_string):
     match = re.search(r"^(-?\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)$",
                       time_string)
     if match:
         year = int(match.group(1))
         month = int(match.group(2))
         day = int(match.group(3))
         hour = int(match.group(4))
         minute = int(match.group(5))
         second = int(match.group(6))
         try:
             return CopticDateTime(year, month, day, hour, minute,
                                   second).to_time()
         except ValueError:
             raise ValueError("Invalid time, time string = '%s'" %
                              time_string)
     else:
         raise ValueError("Time not on correct format = '%s'" % time_string)