当前位置: 首页>>代码示例>>Java>>正文


Java Hours类代码示例

本文整理汇总了Java中org.joda.time.Hours的典型用法代码示例。如果您正苦于以下问题:Java Hours类的具体用法?Java Hours怎么用?Java Hours使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Hours类属于org.joda.time包,在下文中一共展示了Hours类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onSetupComplete

import org.joda.time.Hours; //导入依赖的package包/类
@SuppressLint("ApplySharedPref")
private void onSetupComplete() {
    //download whole leaderboards data asynchronously
    new FetchLeaderBoardDataAsync(this).execute();

    //schedule daily sync at 3:00 am local time
    FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));

    DateTime now = new DateTime();
    DateTime tomorrow = now.plusDays(1).withTimeAtStartOfDay().plusHours(3);
    int windowStart = Hours.hoursBetween(now, tomorrow).getHours() * 60 * 60;
    Job synJob = dispatcher.newJobBuilder()
            .setService(SyncScheduler.class)
            .setTag(Constants.PERIODIC_SYNC_SCHEDULE_KEY)
            .setReplaceCurrent(true)
            .setTrigger(Trigger.executionWindow(windowStart, windowStart + 10))
            .setConstraints(Constraint.ON_ANY_NETWORK)
            .setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
            .build();
    dispatcher.mustSchedule(synJob);

    sharedPreferences.edit().putBoolean(Constants.PREF_FIREBASE_SETUP, true).commit();
    startActivity(new Intent(this, PreChecksActivity.class));
    finish();
}
 
开发者ID:Protino,项目名称:CodeWatch,代码行数:26,代码来源:OnBoardActivity.java

示例2: getHoursBetween

import org.joda.time.Hours; //导入依赖的package包/类
public static int getHoursBetween(final String date1, final String date2, String format){
    try {
    final DateTimeFormatter fmt =
            DateTimeFormat
                    .forPattern(format)
                    .withChronology(
                            LenientChronology.getInstance(
                                    GregorianChronology.getInstance()));
    return Hours.hoursBetween(
            fmt.parseDateTime(date1),
            fmt.parseDateTime(date2)
    ).getHours();
    } catch (Exception ex) {
        ex.printStackTrace();
        return 0;
    }
}
 
开发者ID:Suhas010,项目名称:Artificial-Intelligent-chat-bot-,代码行数:18,代码来源:IntervalUtils.java

示例3: get_interval

import org.joda.time.Hours; //导入依赖的package包/类
private String get_interval(DateTime largerDatetime, DateTime smallerDateTime) throws HydraClientException{
	int year_diff  = Years.yearsBetween(smallerDateTime, largerDatetime).getYears();
	int month_diff  = Months.monthsBetween(smallerDateTime, largerDatetime).getMonths();
	int day_diff  = Days.daysBetween(smallerDateTime, largerDatetime).getDays();
	int hour_diff = Hours.hoursBetween(smallerDateTime, largerDatetime).getHours();
    int min_diff  = Minutes.minutesBetween(smallerDateTime, largerDatetime).getMinutes();
    
    if (year_diff > 0){return year_diff+"YEAR";}
    if (month_diff > 0){return month_diff+"MONTH";}
    if (day_diff > 0){return day_diff+"DAY";}
    if (hour_diff > 0){return hour_diff+"HOUR";}
    if (min_diff > 0){return min_diff+"MIN";}

    throw new HydraClientException("Could not compute interval between times " + smallerDateTime.toString() + "and" + largerDatetime.toString());
	
}
 
开发者ID:UMWRG,项目名称:DSSApp,代码行数:17,代码来源:DSSExport.java

示例4: testHourRuns25TimesInDSTChangeToWinter

import org.joda.time.Hours; //导入依赖的package包/类
@Test
public void testHourRuns25TimesInDSTChangeToWinter() throws Exception {
    CronParser cron = CronParser.create("1 * * * *");
    DateTimeZone timeZone = DateTimeZone.forID("America/New_York");
    DateTime start = new DateTime(2011, 11, 6, 0, 0, 0, timeZone);
    DateTime slutt = start.plusDays(1).withTimeAtStartOfDay();
    DateTime tid = start;
    assertEquals(25, Hours.hoursBetween(start, slutt).getHours());
    int count=0;
    DateTime lastTime = tid;
    while(tid.isBefore(slutt)){
        DateTime nextTime = cron.nextRunDate(tid);
        assertTrue(nextTime.isAfter(lastTime));
        lastTime = nextTime;
        tid = tid.plusHours(1);
        count++;
    }
    assertEquals(25, count);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:20,代码来源:CronTest.java

示例5: testHourRuns23TimesInDSTChangeToSummer

import org.joda.time.Hours; //导入依赖的package包/类
@Test
public void testHourRuns23TimesInDSTChangeToSummer() throws Exception {
    CronParser cron = CronParser.create("1 * * * *");
    DateTimeZone timeZone = DateTimeZone.forID("America/New_York");
    DateTime start = new DateTime(2011, 3, 13, 0, 0, 0, timeZone);
    DateTime slutt = start.plusDays(1).withTimeAtStartOfDay();
    DateTime tid = start;
    assertEquals(23, Hours.hoursBetween(start, slutt).getHours());
    int count=0;
    DateTime lastTime = tid;
    while(tid.isBefore(slutt)){
        DateTime nextTime = cron.nextRunDate(tid);
        assertTrue(nextTime.isAfter(lastTime));
        lastTime = nextTime;
        tid = tid.plusHours(1);
        count++;
    }
    assertEquals(23, count);
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:20,代码来源:CronTest.java

示例6: processEmployeeRules

import org.joda.time.Hours; //导入依赖的package包/类
private double processEmployeeRules(List<Assignment> assignments) {
    double fitness = 0.0;
    for (Employee employee : employees) {
        List<Shift> shifts = assignments.stream()
                                        .filter(a -> a.employee.id == employee.id)
                                        .map(assignment -> assignment.shift)
                                        .collect(Collectors.toList());
        shifts.sort((a, b) -> a.start.compareTo(b.start));
        for (int i = 1; i < shifts.size(); ++i) {
            int timeBetween = Hours.hoursBetween(shifts.get(i - 1).end, shifts.get(i).start).getHours();
            if (timeBetween < restTime) {
                fitness -= HARD_SCORE;
            }
        }
        fitness += shifts.size();
    }
    return fitness;
}
 
开发者ID:jdarc,项目名称:bioforge,代码行数:19,代码来源:Rules.java

示例7: computeTimeModeAndDiff

import org.joda.time.Hours; //导入依赖的package包/类
private int computeTimeModeAndDiff(DateTime dmin, DateTime dmax) {
    int diffDay = Days.daysBetween(dmin, dmax).getDays();
    int diffHou = Hours.hoursBetween(dmin, dmax).getHours();
    int diffMin = Minutes.minutesBetween(dmin, dmax).getMinutes();
    int diffSec = Seconds.secondsBetween(dmin, dmax).getSeconds();

    int diff = diffMin;

    guessTimeMode(diffDay, diffHou, diffMin, diffSec);

    if (TimeMode.DAY.equals(timeMode)) {
        diff = diffDay;
    } else if (TimeMode.HOUR.equals(timeMode)) {
        diff = diffHou;
    } else if (TimeMode.MINUTE.equals(timeMode)) {
        diff = diffMin;
    } else if (TimeMode.SECOND.equals(timeMode)) {
        diff = diffSec;
    }

    //consoleDiffs(diffDay, diffHou, diffMin, diffSec, diff);

    return diff;
}
 
开发者ID:jzy3d,项目名称:bigpicture,代码行数:25,代码来源:HistogramDate.java

示例8: dateToAge

import org.joda.time.Hours; //导入依赖的package包/类
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 "";
    }
}
 
开发者ID:zfoltin,项目名称:twittererer,代码行数:23,代码来源:TimelineConverter.java

示例9: getsNewUnboundToken

import org.joda.time.Hours; //导入依赖的package包/类
@Test
public void getsNewUnboundToken() throws InterruptedException, HodErrorException {
    final CountDownLatch latch = new CountDownLatch(1);
    final List<Try<AuthenticationToken<EntityType.Unbound, TokenType.HmacSha1>>> outputs = Collections.synchronizedList(new ArrayList<Try<AuthenticationToken<EntityType.Unbound,TokenType.HmacSha1>>>());

    final AuthenticationToken<EntityType.Unbound, TokenType.HmacSha1> unboundToken = createToken(Hours.ONE);
    mockAuthenticateUnbound().then(new DelayedAnswer<>(unboundToken));
    mockTokenInformation(unboundToken);

    executorService.execute(new UnboundTokenGetter(unboundTokenService, outputs, latch));
    awaitLatch(latch);

    assertThat(outputs, hasSize(1));
    verify(authenticationService, times(1)).authenticateUnbound(any(ApiKey.class), eq(TokenType.HmacSha1.INSTANCE));
    checkOutput(outputs.get(0), unboundToken, null);
}
 
开发者ID:hpe-idol,项目名称:java-hod-sso-spring-security,代码行数:17,代码来源:UnboundTokenServiceImplTest.java

示例10: getsUnboundTokenFiveTimesButOnlyFetchesOnce

import org.joda.time.Hours; //导入依赖的package包/类
@Test
public void getsUnboundTokenFiveTimesButOnlyFetchesOnce() throws HodErrorException, InterruptedException {
    final int times = 5;
    final CountDownLatch latch = new CountDownLatch(times);
    final List<Try<AuthenticationToken<EntityType.Unbound, TokenType.HmacSha1>>> outputs = Collections.synchronizedList(new ArrayList<Try<AuthenticationToken<EntityType.Unbound,TokenType.HmacSha1>>>());

    final AuthenticationToken<EntityType.Unbound, TokenType.HmacSha1> unboundToken = createToken(Hours.ONE);
    mockAuthenticateUnbound().then(new DelayedAnswer<>(unboundToken));
    mockTokenInformation(unboundToken);

    for (int i = 0; i < times; i++) {
        executorService.execute(new UnboundTokenGetter(unboundTokenService, outputs, latch));
    }

    awaitLatch(latch);

    assertThat(outputs, hasSize(times));
    verify(authenticationService, times(1)).authenticateUnbound(any(ApiKey.class), eq(TokenType.HmacSha1.INSTANCE));

    for (int i = 0; i < times; i++) {
        checkOutput(outputs.get(i), unboundToken, null);
    }
}
 
开发者ID:hpe-idol,项目名称:java-hod-sso-spring-security,代码行数:24,代码来源:UnboundTokenServiceImplTest.java

示例11: getsUnboundTokenAndUUIDButOnlyFetchesOnce

import org.joda.time.Hours; //导入依赖的package包/类
@Test
public void getsUnboundTokenAndUUIDButOnlyFetchesOnce() throws HodErrorException, InterruptedException {
    final int times = 2;
    final CountDownLatch latch = new CountDownLatch(times);
    final List<Try<AuthenticationToken<EntityType.Unbound, TokenType.HmacSha1>>> tokenOutputs = Collections.synchronizedList(new ArrayList<Try<AuthenticationToken<EntityType.Unbound,TokenType.HmacSha1>>>());
    final List<Try<UUID>> authenticationUUIDOutputs = Collections.synchronizedList(new ArrayList<Try<UUID>>());

    final AuthenticationToken<EntityType.Unbound, TokenType.HmacSha1> unboundToken = createToken(Hours.ONE);
    mockAuthenticateUnbound().then(new DelayedAnswer<>(unboundToken));
    mockTokenInformation(unboundToken);

    executorService.execute(new UnboundTokenGetter(unboundTokenService, tokenOutputs, latch));
    executorService.execute(new UnboundAuthenticationUUIDGetter(unboundTokenService, authenticationUUIDOutputs, latch));

    awaitLatch(latch);

    assertThat(tokenOutputs, hasSize(1));
    assertThat(authenticationUUIDOutputs, hasSize(1));
    verify(authenticationService, times(1)).authenticateUnbound(any(ApiKey.class), eq(TokenType.HmacSha1.INSTANCE));

    checkOutput(tokenOutputs.get(0), unboundToken, null);
    checkOutput(authenticationUUIDOutputs.get(0), AUTH_UUID, null);
}
 
开发者ID:hpe-idol,项目名称:java-hod-sso-spring-security,代码行数:24,代码来源:UnboundTokenServiceImplTest.java

示例12: getsUnboundTokenAfterException

import org.joda.time.Hours; //导入依赖的package包/类
@Test
public void getsUnboundTokenAfterException() throws HodErrorException, InterruptedException {
    final List<Try<AuthenticationToken<EntityType.Unbound, TokenType.HmacSha1>>> outputs = Collections.synchronizedList(new ArrayList<Try<AuthenticationToken<EntityType.Unbound,TokenType.HmacSha1>>>());
    final CountDownLatch latch = new CountDownLatch(3);

    final AuthenticationToken<EntityType.Unbound, TokenType.HmacSha1> unboundToken = createToken(Hours.ONE);
    final HodErrorException exception = createException();
    mockAuthenticateUnbound().then(new DelayedAnswer<>(exception)).then(new DelayedAnswer<>(unboundToken));
    mockTokenInformation(unboundToken);

    for (int i = 0; i < 3; i++) {
        executorService.execute(new UnboundTokenGetter(unboundTokenService, outputs, latch));
    }

    awaitLatch(latch);

    assertThat(outputs, hasSize(3));
    verify(authenticationService, times(2)).authenticateUnbound(any(ApiKey.class), eq(TokenType.HmacSha1.INSTANCE));

    checkOutput(outputs.get(0), null, exception);
    checkOutput(outputs.get(1), unboundToken, null);
    checkOutput(outputs.get(2), unboundToken, null);
}
 
开发者ID:hpe-idol,项目名称:java-hod-sso-spring-security,代码行数:24,代码来源:UnboundTokenServiceImplTest.java

示例13: initialise

import org.joda.time.Hours; //导入依赖的package包/类
@Before
public void initialise() throws IOException, HodErrorException {
    tokenProxy = new TokenProxy<>(EntityType.Combined.INSTANCE, TokenType.Simple.INSTANCE);
    applicationAuthenticationUuid = UUID.randomUUID();

    combinedToken = new AuthenticationToken<>(
            EntityType.Combined.INSTANCE,
            TokenType.Simple.INSTANCE,
            DateTime.now().plus(Hours.TWO),
            "token-id",
            "token-secret",
            DateTime.now().plus(Hours.ONE)
    );

    when(tokenRepository.insert(combinedToken)).thenReturn(tokenProxy);
    when(unboundTokenService.getAuthenticationUuid()).thenReturn(applicationAuthenticationUuid);
}
 
开发者ID:hpe-idol,项目名称:java-hod-sso-spring-security,代码行数:18,代码来源:CookieHodAuthenticationProviderTest.java

示例14: onReceive

import org.joda.time.Hours; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(NightscoutMonitor.NEW_READING_ACTION)) {
        int uploaderBattery = Optional.fromNullable(intent.getExtras().getInt("uploaderBattery")).or(-1);
        int receiverBattery = Optional.fromNullable(intent.getExtras().getInt("receiverBattery")).or(-1);
        List<EGVRecord> egvRecords = SgvDbEntry.getLastEgvRecords(new DateTime().minus(Hours.hours(4)));
        updateView(egvRecords, uploaderBattery, receiverBattery);
    } else if (intent.getAction().equals(NightscoutMonitor.RECEIVER_STATE_INTENT)) {
        Optional<String> receiverStatus = Optional.fromNullable(intent.getExtras().getString("state"));
        if (receiverStatus.isPresent()) {
            Log.d("StateReceiver", "Received state: " + receiverStatus.get());
            if (receiverStatus.get().equals(ReceiverStatus.RECEIVER_CONNECTED.name())) {
                receiverButton.setBackgroundResource(R.drawable.ic_usb);
            } else {
                receiverButton.setBackgroundResource(R.drawable.ic_nousb);
            }
        }
    } else if (intent.getAction().equals(NightscoutMonitor.MQTT_RESPONSE_STATUS_INTENT)) {
        int res = (intent.getExtras().getBoolean(NightscoutMonitor.MQTT_STATUS_EXTRA_FIELD)) ? R.drawable.ic_cloud : R.drawable.ic_nocloud;
        uploadButton.setImageResource(res);
    }
}
 
开发者ID:nightscout,项目名称:lasso,代码行数:23,代码来源:MainActivity.java

示例15: user_validateForgotPasswordKey

import org.joda.time.Hours; //导入依赖的package包/类
public boolean user_validateForgotPasswordKey(String hash)  {
	try {

		PasswordResetRequest  passwordResetRequest = passwordResetRequestDAO.findByHash(hash);
		if (passwordResetRequest == null) {log.info("empty return" + hash);}
		if (passwordResetRequest != null && 
			passwordResetRequest.getResetDate() == null) {
			int hours = Hours.hoursBetween(new DateTime(passwordResetRequest.getRequestDate()), new DateTime(new Date())).getHours();
			if (hours <= TIME_INTERVAL_TO_CHANGE_PASSWORD_IN_HOURS ) {
				return true;
			}
		}
		return false; 
	}
	catch (Exception e) {
		log.error(e.getMessage(),e);
		throw (new RuntimeException(e));
	}
}
 
开发者ID:JD-Software,项目名称:JDeSurvey,代码行数:20,代码来源:UserService.java


注:本文中的org.joda.time.Hours类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。