Пример #1
0
 def __new__(cls, *args, **kwargs):
     # print("args: ", args)
     yy = args[0]
     mm = args[1:2][0] if args[1:2] else 0
     dd = args[2:3][0] if args[2:3] else 0
     hh = args[3:4][0] if args[3:4] else 0
     mi = args[4:5][0] if args[4:5] else 0
     ss = args[5:6][0] if args[5:6] else 0
     ms = args[6:7][0] if args[6:7] else 0
     tz = args[7:8][0] if args[7:8] else timezone.utc
     if isinstance(args[0], str):
         yy = parse(args[0])
     if isinstance(yy, datetime):
         tz = yy.tzinfo if yy.tzinfo else timezone.utc
         ms = yy.microsecond
         ss = yy.second
         mi = yy.minute
     if isinstance(yy, date) or isinstance(yy, datetime):
         hh = yy.hour
         dd = yy.day
         mm = yy.month
         yy = yy.year
     vals = tuple([yy, mm, dd, hh, mi, ss, ms, tz])
     try:
         return datetime.__new__(cls, *vals, **kwargs)
     except:
         vals = tuple([1900, 1, 1, 0, 0, 0, 0])
         return datetime.__new__(cls, *vals)
Пример #2
0
 def __new__(cls, dt=None, *args, **kwargs):
   if isinstance(dt, datetime):
     if type(dt) is cls:
       return dt
     return datetime.__new__(cls, 
       dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond, dt.tzinfo)
   return datetime.__new__(cls, dt, *args, **kwargs)
Пример #3
0
 def __new__(cls, *args, **kwargs):
     # print("args: ", args)
     yy = args[0]
     mm = args[1:2][0] if args[1:2] else 0
     dd = args[2:3][0] if args[2:3] else 0
     hh = args[3:4][0] if args[3:4] else 0
     mi = args[4:5][0] if args[4:5] else 0
     ss = args[5:6][0] if args[5:6] else 0
     ms = args[6:7][0] if args[6:7] else 0
     tz = args[7:8][0] if args[7:8] else timezone.utc
     if isinstance(args[0], str):
         yy = parse(args[0])
     if isinstance(yy, datetime):
         tz = yy.tzinfo if yy.tzinfo else timezone.utc
         ms = yy.microsecond
         ss = yy.second
         mi = yy.minute
     if isinstance(yy, date) or isinstance(yy, datetime):
         hh = yy.hour
         dd = yy.day
         mm = yy.month
         yy = yy.year
     vals = tuple([yy, mm, dd, hh, mi, ss, ms, tz])
     try:
         return datetime.__new__(cls, *vals, **kwargs)
     except:
         vals = tuple([1900, 1, 1, 0, 0, 0, 0])
         return datetime.__new__(cls, *vals)
Пример #4
0
 def __new__(cls, year=1980, month=1, day=6, hour=0, minute=0, second=0,
             microsecond=0, tzinfo=gpstz):
     if isinstance(year, str) and isinstance(month, TZInfo):
         return datetime.__new__(cls, year, month)
     elif isinstance(year, str):
         return datetime.__new__(cls, year)
     return datetime.__new__(cls, year, month, day, hour, minute, second,
                             int(microsecond), tzinfo)
Пример #5
0
    def __new__(cls, val, *args):
        # The constructor may be called in various ways:
        #  - T(str), to explicitly convert from a time string
        #  - T(datetime), to explicitly convert from a datetime
        #  - T(int, int, int, int, int, int, int, tzinfo),
        #     used by __add__ and __sub__ in Python 3.8
        #  - T(bytes, tzinfo), used by pickle.loads
        # Only the first two (single argument) forms should be used by
        # applications.

        if args:
            return datetime.__new__(cls, val, *args)

        if isinstance(val, datetime):
            tz = val.tzinfo
            if tz is None:
                raise TypeError('missing timezone')
            return datetime.__new__(
                cls,
                year = val.year,
                month = val.month,
                day = val.day,
                hour = val.hour,
                minute = val.minute,
                second = val.second,
                microsecond = val.microsecond,
                tzinfo = tz)

        m = T._pattern.match(val)
        if m is None:
            raise ValueError('malformed timestamp string %r' % (val,))

        second = int(m.group(6))
        microsecond = round(float(m.group(7) or 0) * 1000000)
        # datetime doesn't support leap seconds, and DWC probably
        # doesn't support them either, but allow for the possibility
        # here just in case.  If there is a leap second, it is
        # silently compressed into the final millisecond of the
        # preceding second; this will result in one or more
        # discontinuities in the record time map.
        if second == 60:
            second = 59
            microsecond = 999000 + microsecond // 1000

        tzs = 1 if m.group(8) == '+' else -1
        tz = timezone(timedelta(hours = tzs * int(m.group(9)),
                                minutes = tzs * int(m.group(10))))

        return datetime.__new__(
            cls,
            year = int(m.group(1)),
            month = int(m.group(2)),
            day = int(m.group(3)),
            hour = int(m.group(4)),
            minute = int(m.group(5)),
            second = second,
            microsecond = microsecond,
            tzinfo = tz)
Пример #6
0
    def __new__(cls, string_or_year, *mdhms):
        """Create a new :class:`modeled.datetime` instance
           by giving either a 
        """
        if isstring(string_or_year):
            dt = base.strptime(string_or_year, cls.format)
            return base.__new__(cls, *dt.timetuple()[:6])

        return base.__new__(cls, string_or_year, *mdhms)
Пример #7
0
    def __new__(cls, string_or_year, *mdhms):
        """Create a new :class:`modeled.datetime` instance
           by giving either a 
        """
        if isstring(string_or_year):
            dt = base.strptime(string_or_year, cls.format)
            return base.__new__(cls, *dt.timetuple()[:6])

        return base.__new__(cls, string_or_year, *mdhms)
Пример #8
0
 def __new__(cls, val, *args, **kwargs):
     if isinstance(val, str):
         date = datetime.strptime(val, "%Y-%m-%dT%H:%M:%S%z")
         return datetime.__new__(cls,
                                 date.year,
                                 date.month,
                                 date.day,
                                 date.hour,
                                 date.minute,
                                 date.second,
                                 tzinfo=date.tzinfo)
     else:
         return datetime.__new__(cls, val, *args, **kwargs)
Пример #9
0
 def __new__(cls,
             year=1980,
             month=1,
             day=6,
             hour=0,
             minute=0,
             second=0,
             microsecond=0,
             tzinfo=gpstz):
     if isinstance(year, str) and isinstance(month, TZInfo):
         return datetime.__new__(cls, year, month)
     elif isinstance(year, str):
         return datetime.__new__(cls, year)
     return datetime.__new__(cls, year, month, day, hour, minute, second,
                             int(microsecond), tzinfo)
Пример #10
0
 def __new__(cls, *args, **kw):
     if len(args) == 1:
         value = args[0]
         if isinstance(value, cls):
             return value
         elif isinstance(value, basestring):
             value = dateutil.parser.parse(value)
             return cls(value.year, value.month, value.day, value.hour, value.minute, value.second, value.microsecond, value.tzinfo)
         elif isinstance(value, datetime):
             return cls(value.year, value.month, value.day, value.hour, value.minute, value.second, value.microsecond, value.tzinfo or tzlocal())
         else:
             return datetime.__new__(cls, *args, **kw)
     else:
         if len(args) < 8 and 'tzinfo' not in kw:
             kw['tzinfo'] = tzlocal()
         return datetime.__new__(cls, *args, **kw)
Пример #11
0
 def __new__(
     cls,
     year: int,
     month: int,
     day: int,
     hour: int,
     minute: int,
     second: int,
     microsecond: int,
     tzinfo: Optional[tzinfo],
     *_: Any,
     **kwargs: Any,
 ) -> datetime:
     return datetime.__new__(
         cls,
         year,
         month,
         day,
         hour,
         minute,
         second,
         microsecond,
         tzinfo=tzinfo,
         **kwargs,
     )
Пример #12
0
 def __new__(cls, dt=datetime.now()):
     if not isinstance(dt, datetime):
         raise TypeError("Wrong type. Should be Datetime")
     self = datetime.__new__(cls, dt.year, dt.month, dt.day, dt.hour,
                             dt.minute, dt.second, dt.microsecond)
     self._dt = dt
     return self
 def __new__(
     cls,
     year,
     month,
     day,
     hour,
     minute,
     second,
     microsecond,
     tzinfo,
     trivia,
     raw,
     **kwargs
 ):  # type: (int, int, int, int, int, int, int, ..., Trivia, ...) -> datetime
     return datetime.__new__(
         cls,
         year,
         month,
         day,
         hour,
         minute,
         second,
         microsecond,
         tzinfo=tzinfo,
         **kwargs
     )
Пример #14
0
    def __new__(cls, initial=None):
        """ Create a CUI compliant DateTime Object, from the initial value
            initial : Either
                    numeric - a timestamps of seconds since 1970-01-01 00:00
                    datetime - a value derived from the datetime module
                    string - a text value in nhs standard format (e.g. 01-Jan-1970 01:20)
                if initial is not provided - defaults to now()
        """

        initial_date = None

        if initial is None:
            initial_date = datetime.now()

        if isinstance(initial, Real):
            initial_date = datetime.utcfromtimestamp(initial)

        if isinstance(initial, str):
            initial_date = datetime.strptime(initial, '%d-%b-%Y %H:%M')

        if isinstance(initial, datetime):
            initial_date = initial

        if initial_date is None:
            raise ValueError(
                'Invalid value for initial argument - must be a numeric, string, datetime, Callable or None')

        return datetime.__new__(cls, initial_date.year, initial_date.month, initial_date.day,
                                initial_date.hour, initial_date.minute, initial_date.second, initial_date.microsecond,
                                initial_date.tzinfo)
Пример #15
0
 def __new__(cls, *args, **kw):
     if len(args) == 1:
         value = args[0]
         if isinstance(value, cls):
             return value
         elif isinstance(value, basestring):
             value = dateutil.parser.parse(value)
             return cls(value.year, value.month, value.day, value.hour, value.minute, value.second, value.microsecond, value.tzinfo)
         elif isinstance(value, datetime):
             return cls(value.year, value.month, value.day, value.hour, value.minute, value.second, value.microsecond, value.tzinfo or tzlocal())
         else:
             return datetime.__new__(cls, *args, **kw)
     else:
         if len(args) < 8 and 'tzinfo' not in kw:
             kw['tzinfo'] = tzlocal()
         return datetime.__new__(cls, *args, **kw)
Пример #16
0
    def __new__(cls,
                year=1970,
                month=1,
                day=1,
                hour=0,
                minute=0,
                second=0,
                microsecond=0,
                tzinfo=None):
        if tzinfo and isinstance(tzinfo, string_types):
            tzinfo = pytz.timezone(tzinfo)

        naive = datetime(year, month, day, hour, minute, second, microsecond)

        if hasattr(tzinfo, 'localize'):
            dt = tzinfo.localize(naive, is_dst=None)
        elif tzinfo:
            dt = naive.replace(tzinfo=tzinfo)
        else:
            dt = pytz.UTC.localize(naive, is_dst=None)

        dt = dt.astimezone(pytz.UTC)

        return datetime.__new__(cls,
                                dt.year,
                                dt.month,
                                dt.day,
                                dt.hour,
                                dt.minute,
                                dt.second,
                                dt.microsecond,
                                dt.tzinfo)
Пример #17
0
 def __new__(cls, *args, **kargs):
     if isinstance(args[0], pydatetime):
         return args[0]
     try:
         return parser.parse(*args, **kargs)
     except TypeError:
         return pydatetime.__new__(cls, *args, **kargs)
Пример #18
0
 def __new__(
     cls,
     year,
     month,
     day,
     hour,
     minute,
     second,
     microsecond,
     tzinfo,
     trivia,
     raw,
     **kwargs
 ):  # type: (int, int, int, int, int, int, int, Optional[datetime.tzinfo], Trivia, str, Any) -> datetime
     return datetime.__new__(
         cls,
         year,
         month,
         day,
         hour,
         minute,
         second,
         microsecond,
         tzinfo=tzinfo,
         **kwargs
     )
Пример #19
0
 def __new__(cls, month=1, day=1, hour=0, minute=0):
     """Create Ladybug datetime."""
     try:
         return datetime.__new__(cls, 2015, month, day, hour, minute)
     except ValueError as e:
         raise ValueError("{} > ({}/{}@{}:{})(m/d@h:m)".format(
             e, month, day, hour, minute))
Пример #20
0
    def __new__(cls, val, _tz=None):
        if isinstance(val, datetime):
            tz = val.tzinfo
            if tz is None:
                raise TypeError('missing timezone')
            return datetime.__new__(cls,
                                    year=val.year,
                                    month=val.month,
                                    day=val.day,
                                    hour=val.hour,
                                    minute=val.minute,
                                    second=val.second,
                                    microsecond=val.microsecond,
                                    tzinfo=tz)
        elif isinstance(val, bytes) and isinstance(_tz, timezone):
            return datetime.__new__(cls, val, _tz)

        m = T._pattern.match(val)
        if m is None:
            raise ValueError('malformed timestamp string')

        second = int(m.group(6))
        microsecond = round(float(m.group(7)) * 1000000)
        # datetime doesn't support leap seconds, and DWC probably
        # doesn't support them either, but allow for the possibility
        # here just in case.  If there is a leap second, it is
        # silently compressed into the final millisecond of the
        # preceding second; this will result in one or more
        # discontinuities in the record time map.
        if second == 60:
            second = 59
            microsecond = 999000 + microsecond // 1000

        tzs = 1 if m.group(8) == '+' else -1
        tz = timezone(
            timedelta(hours=tzs * int(m.group(9)),
                      minutes=tzs * int(m.group(10))))

        return datetime.__new__(cls,
                                year=int(m.group(1)),
                                month=int(m.group(2)),
                                day=int(m.group(3)),
                                hour=int(m.group(4)),
                                minute=int(m.group(5)),
                                second=second,
                                microsecond=microsecond,
                                tzinfo=tz)
Пример #21
0
 def __new__(self, *args, **kwargs):
     if len(args) == 1:
         args = parse(args[0]).timetuple()[:6]
     if len(args) > 2:
         if args[2] == 99:
             args = list(args)
             args[2] = calendar.monthrange(args[0], args[1])[1]
     return basedatetime.__new__(self, *args, **kwargs)
Пример #22
0
	def __new__(cls,*args,**kargs):
		"""
		Adds a new types of constructors for up-casting from a datetime object.
		
		AstroTime(datetime=dt)
		AstroTime(datetime=dt,deltasecs=+33)
		"""
		if (len(args) == 0 and 'datetime' in kargs and
			(len(kargs) == 1 or (len(kargs) == 2 and 'deltasecs' in kargs))):
			if not isinstance(kargs['datetime'],datetime):
				raise AstroTimeException('expect datetime instance')
			deltasecs = kargs['deltasecs'] if 'deltasecs' in kargs else 0
			dt = kargs['datetime'] + timedelta(seconds=deltasecs)
			return datetime.__new__(cls,dt.year,dt.month,dt.day,
				dt.hour,dt.minute,dt.second,dt.microsecond,dt.tzinfo)
		else:
			return datetime.__new__(cls,*args,**kargs)
Пример #23
0
 def __new__(self, *args, **kwargs):
     if len(args) == 1:
         args = parse(args[0]).timetuple()[:6]
     if len(args) > 2:
         if args[2] == 99:
             args = list(args)
             args[2] = calendar.monthrange(args[0], args[1])[1]
     return basedatetime.__new__(self, *args, **kwargs)
Пример #24
0
 def __new__(cls, *args, **kargs):
     """
     Extends constructor to support up-casting from a datetime object.
     
     AstroTime(datetime=dt)
     AstroTime(datetime=dt,deltasecs=+33)
     """
     if (len(args) == 0 and 'datetime' in kargs and
         (len(kargs) == 1 or (len(kargs) == 2 and 'deltasecs' in kargs))):
         if not isinstance(kargs['datetime'], datetime):
             raise AstroTimeException('expect datetime instance')
         deltasecs = kargs['deltasecs'] if 'deltasecs' in kargs else 0
         dt = kargs['datetime'] + timedelta(seconds=deltasecs)
         return datetime.__new__(cls, dt.year, dt.month, dt.day, dt.hour,
                                 dt.minute, dt.second, dt.microsecond,
                                 dt.tzinfo)
     else:
         return datetime.__new__(cls, *args, **kargs)
Пример #25
0
 def __new__(cls, month=1, day=1, hour=0, minute=0):
     """Create Ladybug datetime."""
     hour, minute = cls._calculateHourAndMinute(hour + minute / 60.0)
     try:
         return datetime.__new__(cls, 2015, month, day, hour, minute)
     except ValueError as e:
         raise ValueError("{}:\n\t({}/{}@{}:{})(m/d@h:m)".format(
             e, month, day, hour, minute
         ))
Пример #26
0
 def __new__(cls, month=1, day=1, hour=0, minute=0, leap_year=False):
     """Create Ladybug datetime.
     """
     year = 2016 if leap_year else 2017
     hour, minute = Time._calculate_hour_and_minute(hour + minute / 60.0)
     try:
         return datetime.__new__(cls, year, month, day, hour, minute)
     except ValueError as e:
         raise ValueError("{}:\n\t({}/{}@{}:{})(m/d@h:m)".format(
             e, month, day, hour, minute))
Пример #27
0
 def __new__(self, arg):
    if arg is None:
        return None;
    
    if isinstance(arg, int) or isinstance(arg, long) or isinstance(arg, float):            
        tmp = datetime.utcfromtimestamp(arg)
    else:
        tmp = datetime.utcfromtimestamp(arg.getTime() / 1000)
    return datetime.__new__(self, tmp.year,tmp.month,
           tmp.day, tmp.hour, tmp.minute, tmp.second)
Пример #28
0
 def __new__(self, arg):
    if arg is None:
        return None;
    
    if isinstance(arg, int) or isinstance(arg, long) or isinstance(arg, float):            
        tmp = datetime.utcfromtimestamp(arg)
    else:
        tmp = datetime.utcfromtimestamp(arg.getTime() / 1000)
        
    return datetime.__new__(self, tmp.year,tmp.month,
           tmp.day, tmp.hour, tmp.minute, tmp.second, tzinfo=GMT_ZONE)
Пример #29
0
 def __new__(cls, value, *args, **kwargs):
     if isinstance(value, cls):
         return value
     elif isinstance(value, datetime):
         return cls(value.year, month=value.month, day=value.day,
                    hour=value.hour, minute=value.minute, second=value.second,
                    microsecond=value.microsecond)
     elif isinstance(value, basestring):
         return cls.parse(value)
     else:
         return datetime.__new__(cls, value, *args, **kwargs)
Пример #30
0
    def __new__(cls, *args, **kwargs):
        if cls._LOCAL_TIMEZONE is None:
            raise NotImplementedError("Do not use the AccDatetime class, "
                                      "but one of its children.")
        if len(args) == 1 and isinstance(args[0], datetime):
            dt = args[0]
        else:
            dt = datetime.__new__(cls, *args, **kwargs)

        if dt.tzinfo is None:
            dt = dt.replace(tzinfo=tz.tzutc())

        return datetime.__new__(cls,
                                dt.year,
                                dt.month,
                                dt.day,
                                dt.hour,
                                dt.minute,
                                dt.second,
                                dt.microsecond,
                                tzinfo=dt.tzinfo)
Пример #31
0
    def __new__(cls, year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, is_dst=False):
        """Creates a localized timestamp with the given parameters.
        If tzinfo is omitted, the default time zone will be used."""

        if tzinfo == None:
            tzinfo = _default_tz

        dt = _datetime(year, month, day, hour, minute, second, microsecond)
        dt = tzinfo.localize(dt, is_dst=is_dst)
        return _datetime.__new__(
            cls, dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond, dt.tzinfo
        )
Пример #32
0
 def __new__(cls, value, *_):  # type: (datetime, ...) -> datetime
     return datetime.__new__(
         cls,
         value.year,
         value.month,
         value.day,
         value.hour,
         value.minute,
         value.second,
         value.microsecond,
         tzinfo=value.tzinfo,
     )
Пример #33
0
 def __new__(cls,
             year,
             month=None,
             day=None,
             hour=0,
             minute=0,
             second=0,
             microsecond=0,
             tzinfo=None):
     if tzinfo is None:
         raise ValueError('tzinfo must be specified')
     return datetime.__new__(cls, year, month, day, hour, minute, second,
                             microsecond, tzinfo)
Пример #34
0
    def __new__(cls, year, month, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, is_dst=False):
        """Creates a localized timestamp with the given parameters.
        If tzinfo is omitted, the default time zone will be used."""

        if tzinfo == None:
            tzinfo = _default_tz

        dt = _datetime(year, month, day, hour, minute, second, microsecond)
        dt = tzinfo.localize(dt, is_dst=is_dst)
        return _datetime.__new__(
            cls, dt.year, dt.month, dt.day, 
            dt.hour, dt.minute, dt.second, 
            dt.microsecond, dt.tzinfo)
Пример #35
0
 def __new__(cls, source):
     if isinstance(source, datetime):
         return datetime.__new__(cls,
                                 source.year,
                                 source.month,
                                 source.day,
                                 source.hour,
                                 source.minute,
                                 source.second,
                                 source.microsecond,
                                 source.tzinfo,
                                 fold=source.fold)
     return super().__new__(cls, source)
Пример #36
0
    def __new__(cls, month=1, day=1, hour=0, minute=0):
        """Create Ladybug datetime.

        Returns: a datetime object, 2015, Jan 01 00h 00m by default

        """
        hour, minute = cls._calculateHourAndMinute(hour + minute / 60.0)
        try:
            # super().__new__()
            return datetime.__new__(cls, 2015, month, day, hour, minute)
        except ValueError as e:
            raise ValueError("{}:\n\t({}/{}@{}:{})(m/d@h:m)".format(
                e, month, day, hour, minute
            ))
Пример #37
0
    def __new__(cls, month=1, day=1, hour=0, minute=0):
        """Create Ladybug datetime.

        Args:
            month: A value for month between 1-12. (Defualt: 1)
            day: A value for day between 1-31. (Defualt: 1)
            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 datetime.__new__(cls, 2017, month, day, hour, minute)
        except ValueError as e:
            raise ValueError("{}:\n\t({}/{}@{}:{})(m/d@h:m)".format(
                e, month, day, hour, minute))
Пример #38
0
Файл: dt.py Проект: yvlf/mythtv
 def __new__(cls, year, month, day, hour=None, minute=None, second=None,
                   microsecond=None, tzinfo=None):
     
     if tzinfo is None:
         kwargs = {'tzinfo':cls.localTZ()}
     else:
         kwargs = {'tzinfo':tzinfo}
     if hour is not None:
         kwargs['hour'] = hour
     if minute is not None:
         kwargs['minute'] = minute
     if second is not None:
         kwargs['second'] = second
     if microsecond is not None:
         kwargs['microsecond'] = microsecond
     return _pydatetime.__new__(cls, year, month, day, **kwargs)
Пример #39
0
 def __new__(cls, year, month, day, hour=None, minute=None, second=None,
                   microsecond=None, tzinfo=None):
     
     if tzinfo is None:
         kwargs = {'tzinfo':cls.localTZ()}
     else:
         kwargs = {'tzinfo':tzinfo}
     if hour is not None:
         kwargs['hour'] = hour
     if minute is not None:
         kwargs['minute'] = minute
     if second is not None:
         kwargs['second'] = second
     if microsecond is not None:
         kwargs['microsecond'] = microsecond
     return _pydatetime.__new__(cls, year, month, day, **kwargs)
Пример #40
0
    def __new__(cls, month=1, day=1, hour=0, minute=0, leap_year=False):
        """Create Ladybug datetime.

        Args:
            month: A value for month between 1-12 (Defualt: 1).
            day: A value for day between 1-31 (Defualt: 1).
            hour: A value for hour between 0-23 (Defualt: 0).
            minute: A value for month between 0-59 (Defualt: 0).
            leap_year: A boolean to indicate if datetime is for a leap year
                (Default: False).
        """
        year = 2016 if leap_year else 2017
        hour, minute = cls._calculate_hour_and_minute(hour + minute / 60.0)
        try:
            return datetime.__new__(cls, year, month, day, hour, minute)
        except ValueError as e:
            raise ValueError("{}:\n\t({}/{}@{}:{})(m/d@h:m)".format(
                e, month, day, hour, minute))
Пример #41
0
    def __new__(cls, month=1, day=1, hour=0, minute=0, leap_year=False):
        """Create Ladybug datetime.

        Args:
            month: A value for month between 1-12 (Defualt: 1).
            day: A value for day between 1-31 (Defualt: 1).
            hour: A value for hour between 0-23 (Defualt: 0).
            minute: A value for month between 0-59 (Defualt: 0).
            leap_year: A boolean to indicate if datetime is for a leap year
                (Default: False).
        """
        year = 2016 if leap_year else 2017
        hour, minute = cls._calculate_hour_and_minute(hour + minute / 60.0)
        try:
            return datetime.__new__(cls, year, month, day, hour, minute)
        except ValueError as e:
            raise ValueError("{}:\n\t({}/{}@{}:{})(m/d@h:m)".format(
                e, month, day, hour, minute
            ))
Пример #42
0
 def __new__(cls, *args, **kwargs):
     return datetime.__new__(datetime, *args, **kwargs)
Пример #43
0
 def __new__(cls, *args, **kwargs):
     if len(args) == 1:
         if isinstance(args[0], basetime):
             args = (basedatetime.combine(basedatetime.today(), args[0]), )
         args = parse(args[0]).timetuple()[:6]
     return basedatetime.__new__(cls, *args, **kwargs)
Пример #44
0
 def __new__(cls, *args, **kwargs):
     if len(args) == 1:
         if isinstance(args[0], basetime):
             args = (basedatetime.combine(basedatetime.today(), args[0]), )
         args = parse(args[0]).timetuple()[:6]
     return basedatetime.__new__(cls, *args, **kwargs)
Пример #45
0
 def __new__(cls, year, month=None, day=None, hour=0, minute=0, second=0, microsecond=0, tzinfo=None):
     if tzinfo is None:
         raise ValueError('tzinfo must be specified')
     return datetime.__new__(cls, year, month, day, hour, minute, second, microsecond, tzinfo)
Пример #46
0
    def __new__(cls,
                year=1970,
                month=1,
                day=1,
                hour=0,
                minute=0,
                second=0,
                microsecond=0,
                tzinfo=None,
                *,
                fold=0):
        if (isinstance(year, bytes) and
                len(year) == 10 and
                1 <= year[2] & 0x7F <= 12):
            # Pickle support.
            return cls.fromdatetime(datetime(year, month))
        elif isinstance(year, dict):
            obj = {key: value for key, value in year.items()
                   if key in DATETIME_ATTRS}
            return cls(**obj)

        extra = {'fold': fold} if FOLD_AVAILABLE else {}

        if tzinfo:
            # If tzinfo is provided, we first need to create a stdlib datetime
            # with that tzinfo. Then, we need to convert it to UTC and extract
            # the datetime properites from it so we can then create a Zulu
            # datetime object. We use the stdlib datetime to avoid potential
            # infinite recursion issues if we instead created a Zulu datetime
            # and tried to shift it to UTC.
            tzinfo = parser.get_timezone(tzinfo)

            if hasattr(tzinfo, 'localize'):
                # Support pytz timezones.
                dt = tzinfo.localize(datetime(year,
                                              month,
                                              day,
                                              hour,
                                              minute,
                                              second,
                                              microsecond,
                                              **extra),
                                     is_dst=None)
            else:
                dt = datetime(year,
                              month,
                              day,
                              hour,
                              minute,
                              second,
                              microsecond,
                              tzinfo,
                              **extra)

            if dt.utcoffset() != timedelta(0):
                dt = dt.astimezone(UTC)

            year = dt.year
            month = dt.month
            day = dt.day
            hour = dt.hour
            minute = dt.minute
            second = dt.second
            microsecond = dt.microsecond
            tzinfo = dt.tzinfo

            if FOLD_AVAILABLE:  # pragma: no cover
                fold = extra['fold'] = dt.fold
        else:
            tzinfo = UTC

        return datetime.__new__(cls,
                                year,
                                month,
                                day,
                                hour,
                                minute,
                                second,
                                microsecond,
                                tzinfo,
                                **extra)