(sy, sm, sd) -> term / gz_year / gz_month / gz_day
195408
def _get_gz_ymd(self):
        
        solar_date = MIN_SOLAR_DATE + datetime.timedelta(days=self._offset)
        sy, sm, sd = solar_date.year, solar_date.month, solar_date.day
        s_offset = (datetime.date(sy, sm, sd) - MIN_SOLAR_DATE).days
        gz_year = TextUtils.STEMS[(self.year - 4) % 10] + TextUtils.BRANCHES[(self.year - 4) % 12]
        gz_day = TextUtils.get_gz_cn((s_offset + 40) % 60)
        term_name, next_gz_month = TermUtils.get_term_info(sy, sm, sd)
        if next_gz_month:
            gz_month = TextUtils.get_gz_cn((sy - 1900) * 12 + sm + 12)
        else:
            gz_month = TextUtils.get_gz_cn((sy - 1900) * 12 + sm + 11)
        return gz_year, gz_month, gz_day, term_name
302211
def to_jd(year, month, day):
    ''''''
    legal_date(year, month, day)
    gyear = year + YEAR_EPOCH - 1

    return (
        gregorian.EPOCH - 1 + (365 * (gyear - 1)) +
        floor((gyear - 1) / 4) + (-floor((gyear - 1) / 100)) +
        floor((gyear - 1) / 400) + (month - 1) * 28 + day
    )
725224
def mktime_tz(data):
    """"""
    if data[9] is None:
        # No zone info, so localtime is better assumption than GMT
        return time.mktime(data[:8] + (-1,))
    else:
        t = calendar.timegm(data)
        return t - data[9]
1199164
def U(self):
    ""
    if getattr(self.data, 'tzinfo', None):
      return int(calendar.timegm(self.data.utctimetuple()))
    else:
      return int(time.mktime(self.data.timetuple()))
1151056
function w3calgo(s, d) {
        var carry, temp, tempDays, e = {};
        //months
        temp = s.M + d.M;
        e.M = modulo(temp, 1, 13);
        carry = fQuotient(temp, 1, 13);
        // years
        e.Y = s.Y + d.Y + carry;
        // zone
        // e.Z = s.Z;
        // seconds 
        temp = s.S + d.S;
        e.S = modulo(temp, 60);
        carry = fQuotient(temp, 60);
        // minutes
        temp = s.m + d.m + carry;
        e.m = modulo(temp, 60);
        carry = fQuotient(temp, 60);
        // hours	
        temp = s.H + d.H + carry;
        e.H = modulo(temp, 24);
        carry = fQuotient(temp, 24);
        // days
        if (s.D > maximumDayInMonthFor(e.Y, e.M)) {
            tempDays = maximumDayInMonthFor(e.Y, e.M);
        } else if (s.D < 1) {
            tempDays = 1;
        } else {
            tempDays = s.D;
        }
        e.D = tempDays + d.D + carry;
        // start loop
        while (true) {
            if (e.D < 1) {
                e.D = e.D + maximumDayInMonthFor(e.D, e.M - 1);
                carry = -1;
            } else if (e.D > maximumDayInMonthFor(e.Y, e.M)) {
                e.D = e.D - maximumDayInMonthFor(e.Y, e.M);
                carry = 1;
            } else {
                break;
            }
            temp = e.M + carry;
            e.M = modulo(temp, 1, 13);
            e.Y = e.Y + fQuotient(temp, 1, 13);
        }
        e.Y = e.Y | 0;
        // in js dates month start at 0.
        e.M = e.M - 1 | 0;
        e.D = e.D | 0;
        e.H = e.H | 0;
        e.m = e.m | 0;
        e.S = e.S | 0;
        return new Date(e.Y, e.M, e.D, e.H, e.m, e.S);
    }
1196680
def _get_site_term(self, C, vs30):
        
        dg1, dg2 = self._get_regional_site_term(C)
        return (C["g1"] + dg1) + (C["g2"] + dg2) * np.log(vs30)
196009
def _pack_date(self, date):
        """"""
        
        # Just copied from original KeePassX source
        y, mon, d, h, min_, s = date.timetuple()[:6]

        dw1 = 0x0000FFFF & ((y>>6) & 0x0000003F)
        dw2 = 0x0000FFFF & ((y & 0x0000003F)<<2 | ((mon>>2) & 0x00000003))
        dw3 = 0x0000FFFF & (((mon & 0x0000003)<<6) | ((d & 0x0000001F)<<1) \
                | ((h>>4) & 0x00000001))
        dw4 = 0x0000FFFF & (((h & 0x0000000F)<<4) | ((min_>>2) & 0x0000000F))
        dw5 = 0x0000FFFF & (((min_ & 0x00000003)<<6) | (s & 0x0000003F))

        return struct.pack('<5B', dw1, dw2, dw3, dw4, dw5)
43125
def dosdate(dosdate, dostime):
    
    try:
        t  = ord(dosdate[1]) << 8
        t |= ord(dosdate[0])
        day   = t & 0b0000000000011111
        month = (t & 0b0000000111100000) >> 5
        year  = (t & 0b1111111000000000) >> 9
        year += 1980

        t  = ord(dostime[1]) << 8
        t |= ord(dostime[0])
        sec     = t & 0b0000000000011111
        sec    *= 2
        minute  = (t & 0b0000011111100000) >> 5
        hour    = (t & 0b1111100000000000) >> 11

        return datetime(year, month, day, hour, minute, sec)
    except:
        return datetime.min
126506
def parse_dos_time(stamp):
    
    sec, stamp = stamp & 0x1F, stamp >> 5
    mn,  stamp = stamp & 0x3F, stamp >> 6
    hr,  stamp = stamp & 0x1F, stamp >> 5
    day, stamp = stamp & 0x1F, stamp >> 5
    mon, stamp = stamp & 0x0F, stamp >> 4
    yr = (stamp & 0x7F) + 1980
    return (yr, mon, day, hr, mn, sec * 2)
949489
function toGregorian(oPersian) {
		var iJulianDayNumber = j2d(oPersian.year, oPersian.month + 1, oPersian.day);
		return d2g(iJulianDayNumber);
	}
732728
public static String getZodiac(int month, int day) {
		// 在分隔日前为前一个星座，否则为后一个星座
		return day < dayArr[month] ? ZODIACS[month] : ZODIACS[month + 1];
	}
1234698
def date_struct_nn(year, month, day, tz="UTC"):
    
    if not day:
        day = 1
    if not month:
        month = 1
    return date_struct(year, month, day, tz)
542210
private static String getDaysInMonthBound(int year, int month) {
	    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
		cal.set(Calendar.YEAR, year);
	    cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DAY_OF_MONTH, 1);
		return new Integer(cal.getActualMaximum(Calendar.DAY_OF_MONTH)).toString();
	}
848484
def monthly(usaf, year, field='GHI (W/m^2)'):
    """"""
    m = []
    lastm = 1
    usafdata = Data(usaf, year)
    t = 0
    for r in usafdata:
        r['GHI (W/m^2)'] = r['Glo Mod (Wh/m^2)']
        r['DHI (W/m^2)'] = r['Dif Mod (Wh/m^2)']
        r['DNI (W/m^2)'] = r['Dir Mod (Wh/m^2)']
        if r['datetime'].month != lastm:
            m.append(t/1000.)
            t = 0
            lastm = r['utc_datetime'].month
        t += float(r[field])
    return m
1229600
def gday_of_year(self):
        """"""
        return (self.date - dt.date(self.date.year, 1, 1)).days
1079964
private static String trySkip(StringTokenizer st, String s1, Calendar cal) {
		while (true) {
			TimeZone tz = timeZoneMapping.get(s1);
			if (tz != null) {
				cal.setTimeZone(tz);
				if (!st.hasMoreTokens())
					return null;
				s1 = st.nextToken();
				continue;
			}
			if (voidData.contains(s1)) {
				if (s1.equalsIgnoreCase("pm"))
					cal.add(Calendar.AM_PM, Calendar.PM);
				if (s1.equalsIgnoreCase("am"))
					cal.add(Calendar.AM_PM, Calendar.AM);
				if (!st.hasMoreTokens())
					return null;
				s1 = st.nextToken();
				continue;
			}
			return s1;
		}
	}
1149917
private static int isTodayOrTomorrow(Resources r, long dayMillis,
                                         long currentMillis, long localGmtOffset) {
        int startDay = Time.getJulianDay(dayMillis, localGmtOffset);
        int currentDay = Time.getJulianDay(currentMillis, localGmtOffset);

        int days = startDay - currentDay;
        if (days == 1) {
            return TOMORROW;
        } else if (days == 0) {
            return TODAY;
        } else {
            return NONE;
        }
    }