Create Ladybug Datetime from a minute of the year.

        Args:
            moy: An integer value 0 <= and < 525600
359912
def from_moy(cls, moy, leap_year=False):
        
        if not leap_year:
            num_of_minutes_until_month = (0, 44640, 84960, 129600, 172800, 217440,
                                          260640, 305280, 349920, 393120, 437760,
                                          480960, 525600)
        else:
            num_of_minutes_until_month = (0, 44640, 84960 + 1440, 129600 + 1440,
                                          172800 + 1440, 217440 + 1440, 260640 + 1440,
                                          305280 + 1440, 349920 + 1440, 393120 + 1440,
                                          437760 + 1440, 480960 + 1440, 525600 + 1440)
        # find month
        for monthCount in range(12):
            if int(moy) < num_of_minutes_until_month[monthCount + 1]:
                month = monthCount + 1
                break
        try:
            day = int((moy - num_of_minutes_until_month[month - 1]) / (60 * 24)) + 1
        except UnboundLocalError:
            raise ValueError(
                "moy must be positive and smaller than 525600. Invalid input %d" % (moy)
            )
        else:
            hour = int((moy / 60) % 24)
            minute = int(moy % 60)

            return cls(month, day, hour, minute, leap_year)
750872
def day_of_year(dt):
        # type: (int) -> int
        """"""
        sec = time.mktime(dt.timetuple())
        t = time.localtime(sec)
        return t.tm_yday
520917
def memorized_datetime(seconds):
    ''''''
    try:
        return _datetime_cache[seconds]
    except KeyError:
        # NB. We can't just do datetime.utcfromtimestamp(seconds) as this
        # fails with negative values under Windows (Bug #90096)
        dt = _epoch + timedelta(seconds=seconds)
        _datetime_cache[seconds] = dt
        return dt
275635
def _get_date(data, position, dummy0, opts, dummy1):
    """"""
    end = position + 8
    millis = _UNPACK_LONG(data[position:end])[0]
    return _millis_to_datetime(millis, opts), end
695885
def datetime(past=True, random=random):
    

    def year():
        if past:
            return random.choice(range(1950,2005))
        else:
            return _datetime.datetime.now().year + random.choice(range(1, 50))

    def month():
        return random.choice(range(1,12))

    def day():
        return random.choice(range(1,31))

    def hour():
        return random.choice(range(0,23))

    def minute():
        return random.choice(range(0,59))

    def second():
        return random.choice(range(0,59))

    try:
        return _datetime.datetime(year=year(),
                                  month=month(),
                                  day=day(),
                                  hour=hour(),
                                  minute=minute(),
                                  second=second())
    except ValueError:
        return datetime(past=past)
809003
def _datetime_to_date(arg):
    
    _arg = parse(arg)
    if isinstance(_arg, datetime.datetime):
        _arg = _arg.date()
    return _arg
1212346
def _doy_to_datetimeindex(doy, epoch_year=2014):
    
    doy = np.atleast_1d(doy).astype('float')
    epoch = pd.Timestamp('{}-12-31'.format(epoch_year - 1))
    timestamps = [epoch + dt.timedelta(days=adoy) for adoy in doy]
    return pd.DatetimeIndex(timestamps)
835284
function fromUnixTime(seconds) {
      this.zone = ICAL.Timezone.utcTimezone;
      var epoch = ICAL.Time.epochTime.clone();
      epoch.adjust(0, 0, 0, seconds);

      this.year = epoch.year;
      this.month = epoch.month;
      this.day = epoch.day;
      this.hour = epoch.hour;
      this.minute = epoch.minute;
      this.second = Math.floor(epoch.second);

      this._cachedUnixTime = null;
    }
1013365
def datetime(self):
        ''
        index = self.data.index.remove_unused_levels()
        return pd.to_datetime(index.levels[0])
287245
def get_dst(date_obj):
    """"""
    dst = 0
    if date_obj.year >= 1900:
        tmp_date = time.mktime(date_obj.timetuple())
        # DST is 1 so reduce time with 1 hour.
        dst = time.localtime(tmp_date)[-1]
    return dst
619222
def datetime(self, start: int = 2000, end: int = 2035,
                 timezone: Optional[str] = None) -> DateTime:
        
        datetime_obj = datetime.combine(
            date=self.date(start, end),
            time=self.time(),
        )
        if timezone:
            if not pytz:
                raise ImportError('Timezones are supported only with pytz')
            tz = pytz.timezone(timezone)
            datetime_obj = tz.localize(datetime_obj)

        return datetime_obj
1217888
function setMDY( $month, $day = 0, $year = 0 )
    {
        $arr = getdate( $this->DateTime );
        if ( $year != 0 )
            $date = mktime( $arr['hours'], $arr['minutes'], $arr['seconds'],
                            $month, $day, $year );
        else if ( $day != 0 )
            $date = mktime( $arr['hours'], $arr['minutes'], $arr['seconds'],
                            $month, $day );
        else
            $date = mktime( $arr['hours'], $arr['minutes'], $arr['seconds'],
                            $month );
        $this->DateTime = $date;
    }
1179078
def _muck_w_date(record):
    """"""
    # minute 60 is actually minute 0?
    temp_d = datetime.datetime(int(record['Year']), int(record['Month']),
                               int(record['Day']), int(record['Hour']) % 24,
                               int(record['Minute']) % 60)
    d_off = int(record['Hour'])//24   # hour 24 is actually hour 0
    if d_off > 0:
        temp_d += datetime.timedelta(days=d_off)
    return temp_d
231410
def api_range(
        self, serial: str, date: Optional[timelike] = None
    ) -> SensorRange:
        

        if date is None:
            date = round_time(datetime.now(timezone.utc), by=timedelta(days=1))
        else:
            date = to_datetime(date)
        date = int(date.timestamp())

        c = requests.get(
            f"https://opensky-network.org/api/range/days"
            f"?days={date}&serials={serial}"
        )
        if c.status_code != 200:
            raise ValueError(c.content.decode())
        return SensorRange(c.json())
676255
def enqueued_time(self):
        
        timestamp = self._annotations.get(EventData.PROP_TIMESTAMP, None)
        if timestamp:
            return datetime.datetime.utcfromtimestamp(float(timestamp)/1000)
        return None
705851
def add_years(datetime_like_object, n, return_date=False):
    
    a_datetime = parser.parse_datetime(datetime_like_object)

    # try assign year, month, day
    try:
        a_datetime = datetime(
            a_datetime.year + n, a_datetime.month, a_datetime.day,
            a_datetime.hour, a_datetime.minute, a_datetime.second,
            a_datetime.microsecond, tzinfo=a_datetime.tzinfo,
        )
    except ValueError:  # Must be xxxx-02-29
        a_datetime = datetime(
            a_datetime.year + n, 2, 28,
            a_datetime.hour, a_datetime.minute,
            a_datetime.second, a_datetime.microsecond)

    if return_date:  # pragma: no cover
        return a_datetime.date()
    else:
        return a_datetime
725726
def beautify_date(inasafe_time, feature, parent):
    
    _ = feature, parent  # NOQA
    datetime_object = parse(inasafe_time)
    date = datetime_object.strftime('%Y-%m-%d')
    return date