當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。