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(GregorianDateTime(year, month, day, 0, 0, 0).to_time(),
                      GregorianDateTime(end_year, end_month, end_day, 0, 0, 0).to_time())
Example #2
0
 def _convert_to_datetime(self, d):
     if isinstance(d, datetime):
         return GregorianDateTime(d.year, d.month, d.day, d.hour, d.minute, d.second).to_time()
     elif isinstance(d, date):
         return GregorianDateTime.from_ymd(d.year, d.month, d.day).to_time()
     else:
         raise TimelineIOError("Unknown date.")
Example #3
0
def human_time_to_gregorian(human_time):
    """
    Create a :doc:`GregorianTime <timelinelib.calendar.gregorian.time>` object
    from a human readable date and time string.
    """
    (year, month, day, hour, minute, seconds) = human_time_to_ymdhm(human_time)
    return GregorianDateTime(year, month, day, hour, minute, seconds).to_time()
Example #4
0
 def get_value(self):
     if self.time_picker.IsShown():
         hour, minute, second = self.time_picker.GetGregorianTime()
     else:
         hour, minute, second = (0, 0, 0)
     year, month, day = self.date_picker.GetGregorianDate()
     return GregorianDateTime(year, month, day, hour, minute,
                              second).to_time()
Example #5
0
 def now(self):
     py = datetime.now()
     gregorian = GregorianDateTime(
         py.year,
         py.month,
         py.day,
         py.hour,
         py.minute,
         py.second
     )
     return gregorian.to_time()
Example #6
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 GregorianDateTime(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)
Example #7
0
def _event_from_path(db, file_path):
    stat = os.stat(file_path)
    # st_atime (time of most recent access),
    # st_mtime (time of most recent content modification),
    # st_ctime (platform dependent; time of most recent metadata change on
    #           Unix, or the time of creation on Windows):
    dt = datetime.fromtimestamp(int(stat.st_mtime))
    start_time = GregorianDateTime(dt.year, dt.month, dt.day, dt.hour,
                                   dt.minute, dt.second).to_time()
    end_time = start_time
    if start_time > end_time:
        start_time, end_time = end_time, start_time
    text = os.path.basename(file_path)
    category = _category_from_path(db, file_path)
    evt = Event().update(start_time, end_time, text, category)
    return evt
Example #8
0
 def get_start_end(self):
     now = GregorianDateTime.from_time(self.db.time_type.now())
     start = GregorianDateTime(now.year, now.month, 1, 0, 0, 0).to_time()
     end = start + self.get_delta(30)
     return (start, end)