public static long date2rawtime()

in odps-sdk/odps-sdk-core/src/main/java/com/aliyun/odps/commons/util/DateUtils.java [155:219]


  public static long date2rawtime(Date date, Calendar calendar) {
    //no input parameter verification
    //get literal value of broken-down time regard less of time zone
    Calendar c = null;
    long rawtime;
    int year, mon, day, hour, min, sec;
    long ans;

    c = (Calendar) calendar.clone();
    c.setTime(date);
    c.set(Calendar.MILLISECOND, 0);

    rawtime = date.getTime();
    year = c.get(Calendar.YEAR);
    if (rawtime < _0001_01_01) {
      year = 0;
    }
    mon = c.get(Calendar.MONTH) + 1;
    day = c.get(Calendar.DAY_OF_MONTH);
    hour = c.get(Calendar.HOUR_OF_DAY);
    min = c.get(Calendar.MINUTE);
    sec = c.get(Calendar.SECOND);

    if (rawtime < _0000_03_01) {
      return _0000_01_01_C + ((((mon - 1) * 31 + (day - 1)) * 24 + hour) * 60 + min) * 60 + sec;
    }

    //get literal value of calendar time regard less of time zone
    mon = mon - 2;
    if (mon <= 0) {
      mon += 12;
      year -= 1;
    }
    ans = year / 4 - year / 100 + year / 400 + 367 * mon / 12 + day;
    ans +=
        (year * 365
         - 719499);   //719499 is a gap between 0000-03-01 00:00:00 and 1970-01-01 00:00:00 plus compensation of month
    ans = (((ans * 24 + hour) * 60 + min) * 60) + sec;

    //adjust for time zone
    ans = ans - TZ * 3600;

    //adjust for history
    if (rawtime < _1928_01_01) {
      ans = ans - 352;
    } else if (rawtime >= _1940_06_03_01 && rawtime < _1940_10_01) {
      ans = ans - 3600;
    } else if (rawtime >= _1941_03_16_01 && rawtime < _1941_10_01) {
      ans = ans - 3600;
    } else if (rawtime >= _1986_05_04_01 && rawtime < _1986_09_14) {
      ans = ans - 3600;
    } else if (rawtime >= _1987_04_12_01 && rawtime < _1987_09_13) {
      ans = ans - 3600;
    } else if (rawtime >= _1988_04_10_01 && rawtime < _1988_09_11) {
      ans = ans - 3600;
    } else if (rawtime >= _1989_04_16_01 && rawtime < _1989_09_17) {
      ans = ans - 3600;
    } else if (rawtime >= _1990_04_15_01 && rawtime < _1990_09_16) {
      ans = ans - 3600;
    } else if (rawtime >= _1991_04_14_01 && rawtime < _1991_09_15) {
      ans = ans - 3600;
    }

    return ans;
  }