Java Code Examples for org.joda.time.Seconds#secondsBetween()

The following examples show how to use org.joda.time.Seconds#secondsBetween() . 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: CalculateDateTimeDifference.java    From levelup-java-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void difference_between_two_dates_joda () {
	
	DateTime sinceGraduation = new DateTime(1984, 6, 4, 0, 0, GregorianChronology.getInstance());
	DateTime currentDate = new DateTime(); //current date

	Days diffInDays = Days.daysBetween(sinceGraduation, currentDate);
	Hours diffInHours = Hours.hoursBetween(sinceGraduation, currentDate);
	Minutes diffInMinutes = Minutes.minutesBetween(sinceGraduation, currentDate);
	Seconds seconds = Seconds.secondsBetween(sinceGraduation, currentDate);
	
	logger.info(diffInDays.getDays());
	logger.info(diffInHours.getHours());
	logger.info(diffInMinutes.getMinutes());
	logger.info(seconds.getSeconds());
	
	assertTrue(diffInDays.getDays() >= 10697);
	assertTrue(diffInHours.getHours() >= 256747);
	assertTrue(diffInMinutes.getMinutes() >= 15404876);
	assertTrue(seconds.getSeconds() >= 924292577);

}
 
Example 2
Source File: JobManager.java    From actframework with Apache License 2.0 5 votes vote down vote up
public void on(DateTime instant, Runnable runnable) {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("schedule runnable[%s] on %s", runnable, instant);
    }
    DateTime now = DateTime.now();
    E.illegalArgumentIf(instant.isBefore(now));
    Seconds seconds = Seconds.secondsBetween(now, instant);
    executor().schedule(wrap(runnable), seconds.getSeconds(), TimeUnit.SECONDS);
}
 
Example 3
Source File: JobManager.java    From actframework with Apache License 2.0 5 votes vote down vote up
public <T> Future<T> on(DateTime instant, Callable<T> callable) {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("schedule callable[%s] on %s", callable, instant);
    }
    DateTime now = DateTime.now();
    E.illegalArgumentIf(instant.isBefore(now));
    Seconds seconds = Seconds.secondsBetween(now, instant);
    return executor().schedule(callable, seconds.getSeconds(), TimeUnit.SECONDS);
}
 
Example 4
Source File: JobTrigger.java    From actframework with Apache License 2.0 5 votes vote down vote up
private void delayedSchedule(JobManager manager, Job job) {
    DateTime now = DateTime.now();
    // add one seconds to prevent the next time be the current time (now)
    DateTime next = cronExpr.nextTimeAfter(now.plusSeconds(1));
    Seconds seconds = Seconds.secondsBetween(now, next);
    ScheduledFuture future = manager.executor().schedule(job, seconds.getSeconds(), TimeUnit.SECONDS);
    manager.futureScheduled(job.id(), future);
}
 
Example 5
Source File: TestDateTimeFunctionsBase.java    From presto with Apache License 2.0 4 votes vote down vote up
private static Seconds secondsBetween(ReadableInstant start, ReadableInstant end)
{
    return Seconds.secondsBetween(start, end);
}
 
Example 6
Source File: CucumberHooks.java    From NoraUi with GNU Affero General Public License v3.0 4 votes vote down vote up
protected static int getRemainingTime() {
    DateTime now = DateTime.now();
    Seconds pastTime = Seconds.secondsBetween(Context.getStartCurrentScenario(), now);
    int totalTimecalculated = pastTime.getSeconds() * Context.getDataInputProvider().getNbGherkinExample() / Context.getCurrentScenarioData();
    return totalTimecalculated - pastTime.getSeconds();
}
 
Example 7
Source File: SecondsBetweenDates.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void seconds_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();
	
	Seconds seconds = Seconds.secondsBetween(startDate, endDate);
	
	int secondsInDay = seconds.getSeconds();
	
	assertEquals(86400, secondsInDay);
}