Get date with n unitType before
@param d date
@param n number of units
@param unitType unit type : one of  Calendar.DAY_OF_YEAR, Calendar.WEEK_OF_YEAR, Calendar.MONTH, Calendar.YEAR;
@return
352777
public static Date getLastNDay(Date d, int n, int unitType) {
    	Calendar cal = Calendar.getInstance();
        cal.setTime(d); 
        cal.add(unitType, -n);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
991390
@Override
    public long get(TemporalUnit unit) {

        for (Map.Entry<IsoUnit, TemporalUnit> entry : MAP.entrySet()) {
            if (entry.getValue().equals(unit)) {
                long amount = this.duration.getPartialAmount(entry.getKey());
                if (this.duration.isNegative()) {
                    amount = Math.negateExact(amount);
                }
                return amount;
            }
        }

        if (unit.equals(ChronoUnit.HALF_DAYS)) {
            long hd = Math.floorDiv(this.duration.getPartialAmount(ClockUnit.HOURS), 12);
            if (this.duration.isNegative()) {
                hd = Math.negateExact(hd);
            }
            return hd;
        }

        throw new UnsupportedTemporalTypeException(unit.toString()); // throws NPE if unit is null

    }
1074706
static Date toDate(double d) {
        GregorianCalendar ret = new GregorianCalendar(1899,11,30);
        int days = (int)d;
        d -= days;
        ret.add(Calendar.DATE,days);
        d *= 24;
        int hours = (int)d;
        ret.add(Calendar.HOUR,hours);
        d -= hours;
        d *= 60;
//        d += 0.5; // round
        int min = (int)d;
        ret.add(Calendar.MINUTE,min);

        d -= min;
        d *= 60;
        int secs = (int) d;
        ret.add(Calendar.SECOND, secs);

        return ret.getTime();
    }
579709
def size_in_days(self):
        
        unit, instant, length = self

        if unit == DAY:
            return length
        if unit in [MONTH, YEAR]:
            last_day = self.start.offset(length, unit).offset(-1, DAY)
            return (last_day.date - self.start.date).days + 1

        raise ValueError("Cannot calculate number of days in {0}".format(unit))
253042
private static Date getDate(int day, int month, int year) {
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month);
		cal.set(Calendar.DATE, day);
		return cal.getTime();
	}
118483
def jdToDate(jd):
    ''''''
    if (jd > 2299160):
        # After 5/10/1582, Gregorian calendar
        a = jd + 32044
        b = int((4 * a + 3) / 146097.)
        c = a - int((b * 146097) / 4.)
    else:
        b = 0
        c = jd + 32082
    d = int((4 * c + 3) / 1461.)
    e = c - int((1461 * d) / 4.)
    m = int((5 * e + 2) / 153.)
    day = e - int((153 * m + 2) / 5.) + 1
    month = m + 3 - 12 * int(m / 10.)
    year = b * 100 + d - 4800 + int(m / 10.)
    return [day, month, year]
376317
function(jd) {
        var date = gregorianCalendar.fromJD(jd);
        var year = this._g2tYear(date.year());
        return this.newDate(year, date.month(), date.day());
    }
374628
public static double getJulianDayNumber(Calendar time) {

        if (time == null) {
            time = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
        }

        double jd = BASE_JD + time.getTimeInMillis() / MILLISEC_PER_DAY;

        return jd;
    }
440254
function(d) {
		"use strict";

		if (typeof d === "number") {
			d = new Date(d);
		}
		return new Date(d.getFullYear(), d.getMonth()+1, 0);
	}
1197858
public static JulianDate getJulianEasterSunday (final int nYear)
  {
    final int a = nYear % 4;
    final int b = nYear % 7;
    final int c = nYear % 19;
    final int d = (19 * c + 15) % 30;
    final int e = (2 * a + 4 * b - d + 34) % 7;
    final int x = d + e + 114;
    final int nMonth = x / 31;
    final int nDay = (x % 31) + 1;
    return JulianDate.of (nYear, (nMonth == 3 ? Month.MARCH : Month.APRIL).getValue (), nDay);
  }
330955
@Override  // for covariant return type
    @SuppressWarnings("unchecked")
    public ChronoLocalDateTime<JulianDate> atTime(LocalTime localTime) {
        return (ChronoLocalDateTime<JulianDate>) super.atTime(localTime);
    }
159704
public long between(DateUnit unit) {
		long diff = end.getTime() - begin.getTime();
		return diff / unit.getMillis();
	}
1145876
@Override
    protected PlainDate getDate0(int year) {

        int month = this.getMonthValue();
        int ref = GregorianMath.getDayOfWeek(year, month, this.dayOfMonth);
        PlainDate result = PlainDate.of(year, month, this.dayOfMonth);

        if (ref == this.dayOfWeek) {
            return result;
        }

        int delta = (ref - this.dayOfWeek);
        int sgn = -1;

        if (this.after) {
            delta = -delta;
            sgn = 1;
        }

        if (delta < 0) {
            delta += 7;
        }

        return result.plus(delta * sgn, DAYS);

    }
615728
function addMonths(d, n) {
  var newDate = clone(d);
  newDate.setMonth(d.getMonth() + n);
  return newDate;
}
75196
public static Expression dateAddMillis(String expression, int n, DatePart part) {
        return dateAddMillis(x(expression), n, part);
    }
60061
public static Date getFirstDayFromLastYear(Date d) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);                
        cal.add(Calendar.YEAR, -1);
        cal.set(Calendar.MONTH, Calendar.JANUARY);
        cal.set(Calendar.DAY_OF_MONTH, 1);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
1166792
public static Date getLastDayFromCurrentMonth(Date d) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);                
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DATE));
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 999);
        return cal.getTime();
    }