Esempio n. 1
0
 def read_context(cls, path: Text = None):
     _, context, _, _ = DotFileManager.get_context(path)
     embryo_commands = cls.parse_context(context)
     embryo_commands.sort(key=lambda tup: tup[0])
     used_commands = []
     for timestamp, command in embryo_commands:
         if command in used_commands:
             continue
         if timestamp is not None:
             ts = TimeUtils.from_timestamp(timestamp)
         else:
             ts = None
         used_commands.append((ts, command))
     return used_commands
Esempio n. 2
0
    def process(self, value):
        if isinstance(value, str):
            try:
                dt = dateutil.parser.parse(value)
            except:
                return (None, INVALID_VALUE)
        elif isinstance(value, (int, float)):
            dt = TimeUtils.from_timestamp(value)
        elif isinstance(value, datetime):
            dt = value.replace(tzinfo=self.timezone)
        elif isinstance(value, date):
            dt = datetime.combine(value, datetime.min.time())
        else:
            return (None, UNRECOGNIZED_VALUE)

        if self.format_spec:
            dt_str = datetime.strftime(dt, self.format_spec)
        else:
            dt_str = dt.isoformat()

        return (dt_str, None)
Esempio n. 3
0
 def process(self, value):
     if isinstance(value, datetime):
         return (value.replace(tzinfo=self.tz), None)
     elif isinstance(value, (int, float)):
         try:
             return (TimeUtils.from_timestamp(value).replace(
                 tzinfo=self.tz), None)
         except ValueError:
             return (None, INVALID_VALUE)
     elif isinstance(value, date):
         new_value = datetime.combine(value, datetime.min.time())
         new_value = new_value.replace(tzinfo=self.tz)
         return (new_value, None)
     elif isinstance(value, str):
         try:
             return (dateutil.parser.parse(value).replace(tzinfo=self.tz),
                     None)
         except:
             return (None, INVALID_VALUE)
     else:
         return (None, UNRECOGNIZED_VALUE)