Exemplo n.º 1
0
Arquivo: mtc.py Projeto: jaboja/MTC
    def __new__(cls,
                sol=0,
                hour=0,
                minute=0,
                second=0,
                microsecond=0,
                tzinfo=None):
        """Constructor.

		Arguments:

		sol, hour, minute (required)
		second, microsecond (default to zero)
		tzinfo (default to None)
		"""

        if not isinstance(sol, int):
            raise TypeError('int expected')

        if isinstance(hour, bytes):
            # Pickle (lack of) support
            raise NotImplementedError()

        if tzinfo is None:
            tzinfo = MTC()
        elif not isinstance(tzinfo, MTC):
            raise TypeError('tzinfo argument must be MTC')

        self = time.__new__(cls, hour, minute, second, microsecond)
        self._sol = sol
        self._tzinfo = tzinfo
        return self
Exemplo n.º 2
0
 def __new__(cls, hour=0, minute=0):
     """Create Ladybug Time.
     """
     hour, minute = cls._calculate_hour_and_minute(hour + minute / 60.0)
     try:
         return time.__new__(cls, hour, minute)
     except ValueError as e:
         raise ValueError("{}:\n\t({}:{})(h:m)".format(e, hour, minute))
Exemplo n.º 3
0
    def __new__(cls, hour=0, minute=0):
        '''
        Constructor, arguments exactly like the time class, except also
        can take a time object in the first parameter for casting,
        ignoring anything but the hour and minute.
        '''

        if isinstance(hour, time):
            self = time.__new__(cls, hour=hour.hour, minute=hour.minute)
        elif isinstance(hour,
                        bytes) and len(hour) == 6 and hour[0] & 0x7F < 24:
            # Pickle support
            self = time.__new__(cls, hour)
        else:
            self = time.__new__(cls, hour, minute)
        self._horizon = self.day_transition_hour()

        return self
Exemplo n.º 4
0
 def __new__(
     cls,
     hour: int,
     minute: int,
     second: int,
     microsecond: int,
     tzinfo: Optional[tzinfo],
     *_: Any,
 ) -> time:
     return time.__new__(cls, hour, minute, second, microsecond, tzinfo)
Exemplo n.º 5
0
    def __new__(cls, **kwargs):
        hour_minute = {
            'hour': kwargs.get('hour', 0),
            'minute': kwargs.get('minute', 0),
        }

        if hour_minute['minute'] % 5 != 0:
            raise TypeError(
                "Time must be in 5-minute increments, was {}".format(repr(kwargs)))

        return time.__new__(cls, **hour_minute)
Exemplo n.º 6
0
    def __new__(cls, hour=0, minute=0):
        """Create Ladybug Time.

        Args:
            hour: A value for hour between 0-23 (Defualt: 0).
            minute: A value for month between 0-59 (Defualt: 0).
        """
        hour, minute = cls._calculate_hour_and_minute(hour + minute / 60.0)
        try:
            return time.__new__(cls, hour, minute)
        except ValueError as e:
            raise ValueError("{}:\n\t({}:{})(h:m)".format(e, hour, minute))
Exemplo n.º 7
0
 def __new__(cls, *args, **kwargs):
     hh = args[0]
     mi = args[1:2][0] if args[1:2] else 0
     ss = args[2:3][0] if args[2:3] else 0
     ms = args[3:4][0] if args[3:4] else 0
     tz = args[4:5][0] if args[4:5] else timezone.utc
     if isinstance(args[0], str):
         hh = parse(args[0])
     if isinstance(hh, datetime) or isinstance(hh, time):
         tz = hh.tzinfo if hh.tzinfo else timezone.utc
         ms = hh.microsecond
         ss = hh.second
         mi = hh.minute
         hh = hh.hour
     vals = tuple([hh, mi, ss, ms, tz])
     return time.__new__(cls, *vals, **kwargs)
Exemplo n.º 8
0
 def __new__(cls, *args, **kwargs):
     hh = args[0]
     mi = args[1:2][0] if args[1:2] else 0
     ss = args[2:3][0] if args[2:3] else 0
     ms = args[3:4][0] if args[3:4] else 0
     tz = args[4:5][0] if args[4:5] else timezone.utc
     if isinstance(args[0], str):
         hh = parse(args[0])
     if isinstance(hh, datetime) or isinstance(hh, time):
         tz = hh.tzinfo if hh.tzinfo else timezone.utc
         ms = hh.microsecond
         ss = hh.second
         mi = hh.minute
         hh = hh.hour
     vals = tuple([hh, mi, ss, ms, tz])
     return time.__new__(cls, *vals, **kwargs)
Exemplo n.º 9
0
 def __new__(cls, value, *_):  # type: (time, ...) -> time
     return time.__new__(cls, value.hour, value.minute, value.second,
                         value.microsecond)
Exemplo n.º 10
0
 def __new__(self, *args, **kwargs):
     if len(args) == 1:
         args = parse(args[0]).timetuple()[3:6]
     return basetime.__new__(self, *args, **kwargs)
 def __new__(
     cls, hour, minute, second, microsecond, tzinfo, *_
 ):  # type: (int, int, int, int, ...) -> time
     return time.__new__(cls, hour, minute, second, microsecond, tzinfo)
 def __new__(cls, hour=0, minute=0, second=0, microsecond=0):
     self = time.__new__(cls, hour, minute, second,
                                             microsecond, None)
     return self
Exemplo n.º 13
0
 def __new__(
     cls, hour, minute, second, microsecond, tzinfo, *_
 ):  # type: (int, int, int, int, Optional[datetime.tzinfo], Any) -> time
     return time.__new__(cls, hour, minute, second, microsecond, tzinfo)
Exemplo n.º 14
0
 def __new__(self, *args, **kwargs):
     if len(args) == 1:
         args = parse(args[0]).timetuple()[3:6]
     return basetime.__new__(self, *args, **kwargs)