org.joda.time.Days Java Examples

The following examples show how to use org.joda.time.Days. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TpcdsRecordSet.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public long getLong(int field)
{
    checkState(row != null, "No current row");
    Column column = columns.get(field);
    if (column.getType().getBase() == ColumnType.Base.DATE) {
        return Days.daysBetween(new LocalDate(0), LocalDate.parse(row.get(column.getPosition()))).getDays();
    }
    if (column.getType().getBase() == ColumnType.Base.TIME) {
        return LocalTime.parse(row.get(column.getPosition())).getMillisOfDay();
    }
    if (column.getType().getBase() == ColumnType.Base.INTEGER) {
        return parseInt(row.get(column.getPosition()));
    }
    if (column.getType().getBase() == ColumnType.Base.DECIMAL) {
        DecimalParseResult decimalParseResult = Decimals.parse(row.get(column.getPosition()));
        return rescale((Long) decimalParseResult.getObject(), decimalParseResult.getType().getScale(), ((DecimalType) columnTypes.get(field)).getScale());
    }
    return parseLong(row.get(column.getPosition()));
}
 
Example #2
Source File: BusInfoWindowAdapter.java    From android-app with GNU General Public License v2.0 6 votes vote down vote up
private String prepareDate(Date date){
    DateTime busTimestamp = new DateTime(date);
    DateTime now = new DateTime(Calendar.getInstance());

    int time = Seconds.secondsBetween(busTimestamp, now).getSeconds();
    if(time < 60) return context.getString(R.string.marker_seconds, String.valueOf(time));

    time = Minutes.minutesBetween(busTimestamp, now).getMinutes();
    if(time < 60) return context.getString(R.string.marker_minutes, String.valueOf(time));

    time = Hours.hoursBetween(busTimestamp, now).getHours();
    if(time < 24) return context.getString(R.string.marker_hours, String.valueOf(time));

    time = Days.daysBetween(busTimestamp, now).getDays();
    return context.getString(R.string.marker_days, String.valueOf(time));
}
 
Example #3
Source File: DateTimeFunctions.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the number of days between two dates.
 */
@Function("DAYS")
@FunctionParameters({
	@FunctionParameter("startDate"),
	@FunctionParameter("endDate")})
public Integer DAYS(Object startDate, Object endDate){
	Date startDateObj = convertDateObject(startDate);
	if(startDateObj==null) {
		logCannotConvertToDate();
		return null;
	}
	Date endDateObj = convertDateObject(endDate);
	if(endDateObj==null){
		logCannotConvertToDate();
		return null;
	}
	else{
		LocalDate dt1=new LocalDate(startDateObj);
		LocalDate dt2=new LocalDate(endDateObj);
		return Days.daysBetween(dt1, dt2).getDays();
	}
}
 
Example #4
Source File: DateUtils.java    From xmu-2016-MrCode with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获得两个时间点之间的时间跨度
 * 
 * @param time1
 *            开始的时间点
 * @param time2
 *            结束的时间点
 * @param timeUnit
 *            跨度的时间单位 see {@link JodaTime}
 *            (支持的时间单位有DAY,HOUR,MINUTE,SECOND,MILLI)
 */
public static long lengthBetween(DateTime time1, DateTime time2,
		DurationFieldType timeUnit) {
	Duration duration = Days.daysBetween(time1, time2).toStandardDuration();
	if (timeUnit == JodaTime.DAY) {
		return duration.getStandardDays();
	} else if (timeUnit == JodaTime.HOUR) {
		return duration.getStandardHours();
	} else if (timeUnit == JodaTime.MINUTE) {
		return duration.getStandardMinutes();
	} else if (timeUnit == JodaTime.SECOND) {
		return duration.getStandardSeconds();
	} else if (timeUnit == JodaTime.MILLI) {
		return duration.getMillis();
	} else {
		throw new RuntimeException(
				"TimeUnit not supported except DAY,HOUR,MINUTE,SECOND,MILLI");
	}
}
 
Example #5
Source File: BaseSingleFieldPeriodRelay.java    From jfixture with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("EqualsBetweenInconvertibleTypes") // SpecimenType knows how to do equals(Class<?>)
public Object create(Object request, SpecimenContext context) {

    if (!(request instanceof SpecimenType)) {
        return new NoSpecimen();
    }

    SpecimenType type = (SpecimenType) request;
    if (!BaseSingleFieldPeriod.class.isAssignableFrom(type.getRawType())) {
        return new NoSpecimen();
    }

    Duration duration = (Duration) context.resolve(Duration.class);
    if (type.equals(Seconds.class)) return Seconds.seconds(Math.max(1, (int) duration.getStandardSeconds()));
    if (type.equals(Minutes.class)) return Minutes.minutes(Math.max(1, (int) duration.getStandardMinutes()));
    if (type.equals(Hours.class)) return Hours.hours(Math.max(1, (int) duration.getStandardHours()));

    if (type.equals(Days.class)) return Days.days(Math.max(1, (int) duration.getStandardDays()));
    if (type.equals(Weeks.class)) return Weeks.weeks(Math.max(1, (int) duration.getStandardDays() / 7));
    if (type.equals(Months.class)) return Months.months(Math.max(1, (int) duration.getStandardDays() / 30));
    if (type.equals(Years.class)) return Years.years(Math.max(1, (int) duration.getStandardDays() / 365));

    return new NoSpecimen();
}
 
Example #6
Source File: TimelineConverter.java    From twittererer with Apache License 2.0 6 votes vote down vote up
private static String dateToAge(String createdAt, DateTime now) {
    if (createdAt == null) {
        return "";
    }

    DateTimeFormatter dtf = DateTimeFormat.forPattern(DATE_TIME_FORMAT);
    try {
        DateTime created = dtf.parseDateTime(createdAt);

        if (Seconds.secondsBetween(created, now).getSeconds() < 60) {
            return Seconds.secondsBetween(created, now).getSeconds() + "s";
        } else if (Minutes.minutesBetween(created, now).getMinutes() < 60) {
            return Minutes.minutesBetween(created, now).getMinutes() + "m";
        } else if (Hours.hoursBetween(created, now).getHours() < 24) {
            return Hours.hoursBetween(created, now).getHours() + "h";
        } else {
            return Days.daysBetween(created, now).getDays() + "d";
        }
    } catch (IllegalArgumentException e) {
        return "";
    }
}
 
Example #7
Source File: Reminder.java    From RememBirthday with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create default auto message for date of anniversary
 */
public Reminder(Date dateEvent, int minuteBeforeEvent) {
    this.id = ID_UNDEFINED;
    this.dateEvent = dateEvent;
    this.dateEvent = new DateTime(this.dateEvent)
            .withHourOfDay(0)
            .withMinuteOfHour(0)
            .withSecondOfMinute(0)
            .withMillisOfSecond(0)
            .toDate();
    DateTime dateReminder = new DateTime(dateEvent).minusMinutes(minuteBeforeEvent);
    this.hourOfDay = dateReminder.getHourOfDay();
    this.minuteOfHour = dateReminder.getMinuteOfHour();
    this.daysBefore = Days.daysBetween(dateReminder, new DateTime(dateEvent)).getDays();
    if(minuteBeforeEvent > 0)
        this.daysBefore++;
}
 
Example #8
Source File: ISODaysBetween.java    From spork with Apache License 2.0 6 votes vote down vote up
@Override
public Long exec(Tuple input) throws IOException
{
    if (input == null || input.size() < 2) {
        return null;
    }

    if (input.get(0) == null || input.get(1) == null) {
        return null;
    }

    DateTime startDate = new DateTime(input.get(0).toString());
    DateTime endDate = new DateTime(input.get(1).toString());

    // Larger date first
    Days d = Days.daysBetween(endDate, startDate);
    long days = d.getDays();

    return days;

}
 
Example #9
Source File: DatetimeUtil.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
protected static int dateDiff(Date beginDate, Date endDate, DateType type) {
    //Interval interval = new Interval(beginDate.getTime(), endDate.getTime());
    //Period p = interval.toPeriod();
    DateTime start =new DateTime(beginDate);
    DateTime end =new DateTime(endDate);
    if (DateType.YEAR.equals(endDate)) {
         return Years.yearsBetween(start, end).getYears();
    } else if (DateType.MONTH.equals(type)) {
        return Months.monthsBetween(start, end).getMonths();
    } else if (DateType.WEEK.equals(type)) {
        return Weeks.weeksBetween(start, end).getWeeks();
    } else if (DateType.DAY.equals(type)) {
        return Days.daysBetween(start, end).getDays();
    } else if (DateType.HOUR.equals(type)) {
        return Hours.hoursBetween(start, end).getHours();
    } else if (DateType.MINUTE.equals(type)) {
        return Minutes.minutesBetween(start, end).getMinutes();
    } else if (DateType.SECOND.equals(type)) {
        return Seconds.secondsBetween(start, end).getSeconds();
    } else {
        return 0;
    }
}
 
Example #10
Source File: TempTablesCleaner.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
public TempTablesCleaner(RxSession session, DataAccessImpl dataAccess, String keyspace, int ttl) {
    this.session = session;
    this.dataAccess = dataAccess;
    this.ttl = Days.days(ttl).toStandardDuration().getMillis();

    findTables = session.getSession().prepare(
            "SELECT table_name FROM system_schema.tables WHERE keyspace_name = '" + keyspace + "'");
}
 
Example #11
Source File: SixMonthlyExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceExpiryDays() {
    LocalDate periodDate = new LocalDate();
    int previousPeriodStart = getPreviousPeriodStart();
    periodDate = periodDate.withMonthOfYear(
            previousPeriodStart == PREVIOUS_PERIOD_START_JANUARY ? DateTimeConstants.JANUARY
                    : DateTimeConstants.JULY).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusMonths(6), new LocalDate()).getDays();
    SixMonthlyExpiryDayValidator monthlyExpiryDayValidator = new SixMonthlyExpiryDayValidator(
            expiryDays,
            periodDate.toString(PATTERN) + previousPeriodStart);
    assertFalse(monthlyExpiryDayValidator.canEdit());
}
 
Example #12
Source File: MonthlyExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceMinusOneExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusMonths(1).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusMonths(1), new LocalDate()).getDays() - 1;
    MonthlyExpiryDayValidator monthlyExpiryDayValidator = new MonthlyExpiryDayValidator(
            expiryDays,
            periodDate.toString(PATTERN));
    assertFalse(monthlyExpiryDayValidator.canEdit());
}
 
Example #13
Source File: SixMonthlyAprilExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferencePlusOneExpiryDays() {
    LocalDate periodDate = new LocalDate();
    int previousPeriodStart = getPreviousPeriodStart();
    periodDate = periodDate.withMonthOfYear(
            previousPeriodStart == PREVIOUS_PERIOD_START_APRIL ? DateTimeConstants.APRIL
                    : DateTimeConstants.OCTOBER).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusMonths(6), new LocalDate()).getDays() + 1;
    SixMonthlyAprilExpiryDayValidator monthlyExpiryDayValidator =
            new SixMonthlyAprilExpiryDayValidator(
                    expiryDays,
                    periodDate.toString(PATTERN) + previousPeriodStart);
    assertFalse(monthlyExpiryDayValidator.canEdit());
}
 
Example #14
Source File: SixMonthlyAprilExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceMinusOneExpiryDays() {
    LocalDate periodDate = new LocalDate();
    int previousPeriodStart = getPreviousPeriodStart();
    periodDate = periodDate.withMonthOfYear(
            previousPeriodStart == PREVIOUS_PERIOD_START_APRIL ? DateTimeConstants.APRIL
                    : DateTimeConstants.OCTOBER).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusMonths(6), new LocalDate()).getDays() - 1;
    SixMonthlyAprilExpiryDayValidator monthlyExpiryDayValidator =
            new SixMonthlyAprilExpiryDayValidator(
                    expiryDays,
                    periodDate.toString(PATTERN) + previousPeriodStart);
    assertFalse(monthlyExpiryDayValidator.canEdit());
}
 
Example #15
Source File: YearlyExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusYears(1).withMonthOfYear(
            DateTimeConstants.JANUARY).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusYears(1), new LocalDate()).getDays();
    YearlyExpiryDayValidator yearlyExpiryDayValidator = new YearlyExpiryDayValidator(
            expiryDays,
            periodDate.toString(PATTERN));
    assertFalse(yearlyExpiryDayValidator.canEdit());
}
 
Example #16
Source File: WeeklySundayExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanEditPreviousPeriodEndsSameTodayMinusExpiryDaysPlusOne() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.SUNDAY);
    int expiryDays = Days.daysBetween(periodDate.plusDays(6), new LocalDate()).getDays() + 1;
    WeeklySundayExpiryDayValidator weeklyExpiryDayValidator =
            new WeeklySundayExpiryDayValidator(expiryDays,
                    periodDate.toString(PATTERN));
    assertTrue(weeklyExpiryDayValidator.canEdit());
}
 
Example #17
Source File: YearlyExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferencePlusOneExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusYears(1).withMonthOfYear(
            DateTimeConstants.JANUARY).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusYears(1), new LocalDate()).getDays() + 1;
    YearlyExpiryDayValidator yearlyExpiryDayValidator = new YearlyExpiryDayValidator(
            expiryDays,
            periodDate.toString(PATTERN));
    assertFalse(yearlyExpiryDayValidator.canEdit());
}
 
Example #18
Source File: FinancialYearOctExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusYears(1).withMonthOfYear(
            DateTimeConstants.OCTOBER).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusYears(1), new LocalDate()).getDays();
    FinancialYearOctExpiryDayValidator yearlyExpiryDayValidator =
            new FinancialYearOctExpiryDayValidator(
                    expiryDays,
                    periodDate.toString(PATTERN));
    assertFalse(yearlyExpiryDayValidator.canEdit());
}
 
Example #19
Source File: FinancialYearOctExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferencePlusOneExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusYears(1).withMonthOfYear(
            DateTimeConstants.OCTOBER).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusYears(1), new LocalDate()).getDays() + 1;
    FinancialYearOctExpiryDayValidator yearlyExpiryDayValidator =
            new FinancialYearOctExpiryDayValidator(
                    expiryDays,
                    periodDate.toString(PATTERN));
    assertFalse(yearlyExpiryDayValidator.canEdit());
}
 
Example #20
Source File: SixMonthlyAprilExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanEditWithPeriodPreviousMonthWithTwoMoreDaysAtExpiryDays() {
    LocalDate periodDate = new LocalDate();
    int previousPeriodStart = getPreviousPeriodStart();
    periodDate = periodDate.withMonthOfYear(
            previousPeriodStart == PREVIOUS_PERIOD_START_APRIL ? DateTimeConstants.APRIL
                    : DateTimeConstants.OCTOBER).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusMonths(6), new LocalDate()).getDays() + 2;
    SixMonthlyAprilExpiryDayValidator monthlyExpiryDayValidator =
            new SixMonthlyAprilExpiryDayValidator(
                    expiryDays,
                    periodDate.toString(PATTERN) + previousPeriodStart);
    assertTrue(monthlyExpiryDayValidator.canEdit());
}
 
Example #21
Source File: WeeklySundayExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.SUNDAY);
    int expiryDays = Days.daysBetween(periodDate.plusDays(6), new LocalDate()).getDays();
    WeeklySundayExpiryDayValidator weeklyExpiryDayValidator =
            new WeeklySundayExpiryDayValidator(expiryDays,
                    periodDate.toString(PATTERN));
    assertFalse(weeklyExpiryDayValidator.canEdit());
}
 
Example #22
Source File: WeeklySaturdayExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.SATURDAY);
    int expiryDays = Days.daysBetween(periodDate.plusDays(6), new LocalDate()).getDays();
    WeeklySaturdayExpiryDayValidator weeklyExpiryDayValidator =
            new WeeklySaturdayExpiryDayValidator(expiryDays,
                    periodDate.toString(PATTERN));
    assertFalse(weeklyExpiryDayValidator.canEdit());
}
 
Example #23
Source File: DilbertFragmentAdapter.java    From Simple-Dilbert with Apache License 2.0 5 votes vote down vote up
DilbertFragmentAdapter(FragmentManager fm, DilbertPreferences preferences) {
    super(fm);
    this.countCache = Days.daysBetween(
            DilbertPreferences.getFirstStripDate(),
            LocalDate.now()).getDays() + 1;
    this.preferences = preferences;
}
 
Example #24
Source File: WeeklyThursdayExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceMinusOneExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.THURSDAY);
    int expiryDays = Days.daysBetween(periodDate.plusDays(6), new LocalDate()).getDays() - 1;
    WeeklyThursdayExpiryDayValidator weeklyExpiryDayValidator =
            new WeeklyThursdayExpiryDayValidator(expiryDays,
                    periodDate.toString(PATTERN));
    assertFalse(weeklyExpiryDayValidator.canEdit());
}
 
Example #25
Source File: WeeklyThursdayExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusWeeks(1).withDayOfWeek(DateTimeConstants.THURSDAY);
    int expiryDays = Days.daysBetween(periodDate.plusDays(6), new LocalDate()).getDays();
    WeeklyThursdayExpiryDayValidator weeklyExpiryDayValidator =
            new WeeklyThursdayExpiryDayValidator(expiryDays,
                    periodDate.toString(PATTERN));
    assertFalse(weeklyExpiryDayValidator.canEdit());
}
 
Example #26
Source File: UserService.java    From JDeSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean user_validateDateofBirthAndLogin(String login, Date dob)  {
	try {
		User user = userDAO.findByLogin(login);
		if(user == null){
			return false; //login not found
		}
		//check the provided dob against the database	
		int days = Days.daysBetween(new DateTime(user.getDateOfBirth()), new DateTime(dob)).getDays();
		if (days == 0 ) {return true;}	else {return false;	}
	}
	catch (Exception e) {
		log.error(e.getMessage(),e);
		throw (new RuntimeException(e));
	}
}
 
Example #27
Source File: FinancialYearJulyExpiryDayValidatorTest.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCanNotEditPreviousPeriodEndsSameTodayMinusDifferenceMinusOneExpiryDays() {
    LocalDate periodDate = new LocalDate();
    periodDate = periodDate.minusYears(1).withMonthOfYear(
            DateTimeConstants.JULY).withDayOfMonth(1);
    int expiryDays = Days.daysBetween(periodDate.plusYears(1), new LocalDate()).getDays() - 1;
    FinancialYearJulyExpiryDayValidator yearlyExpiryDayValidator =
            new FinancialYearJulyExpiryDayValidator(
                    expiryDays,
                    periodDate.toString(PATTERN));
    assertFalse(yearlyExpiryDayValidator.canEdit());
}
 
Example #28
Source File: TimeSeriesUtils.java    From skywalking with Apache License 2.0 5 votes vote down vote up
/**
 * Follow the dayStep to re-format the time bucket literal long value.
 *
 * Such as, in dayStep == 11,
 *
 * 20000105 re-formatted time bucket is 20000101, 20000115 re-formatted time bucket is 20000112, 20000123
 * re-formatted time bucket is 20000123
 */
static long compressTimeBucket(long timeBucket, int dayStep) {
    if (dayStep > 1) {
        DateTime time = TIME_BUCKET_FORMATTER.parseDateTime("" + timeBucket);
        int days = Days.daysBetween(DAY_ONE, time).getDays();
        int groupBucketOffset = days % dayStep;
        return Long.parseLong(time.minusDays(groupBucketOffset).toString(TIME_BUCKET_FORMATTER));
    } else {
        /**
         * No calculation required. dayStep is for lower traffic. For normally configuration, there is pointless to calculate.
         */
        return timeBucket;
    }
}
 
Example #29
Source File: SQLDate.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
   public NumberDataValue minus(DateTimeDataValue leftOperand, DateTimeDataValue rightOperand, NumberDataValue returnValue) throws StandardException {
	if( returnValue == null)
		returnValue = new SQLInteger();
	if(leftOperand.isNull() || rightOperand.isNull()) {
		returnValue.restoreToNull();
		return returnValue;
	}
	DateTime thatDate = rightOperand.getDateTime();
	Days diff = Days.daysBetween(thatDate, leftOperand.getDateTime());
	returnValue.setValue(diff.getDays());
	return returnValue;
}
 
Example #30
Source File: DaysBetweenDates.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void days_between_two_dates_in_java_with_joda () {
	
	// start day is 1 day in the past
	DateTime startDate = new DateTime().minusDays(1);
	DateTime endDate = new DateTime();
	
	Days d = Days.daysBetween(startDate, endDate);
	int days = d.getDays();
	
	assertEquals(1, days);
}