當前位置: 首頁>>代碼示例>>Java>>正文


Java DateTimeUtils.setCurrentMillisSystem方法代碼示例

本文整理匯總了Java中org.joda.time.DateTimeUtils.setCurrentMillisSystem方法的典型用法代碼示例。如果您正苦於以下問題:Java DateTimeUtils.setCurrentMillisSystem方法的具體用法?Java DateTimeUtils.setCurrentMillisSystem怎麽用?Java DateTimeUtils.setCurrentMillisSystem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.joda.time.DateTimeUtils的用法示例。


在下文中一共展示了DateTimeUtils.setCurrentMillisSystem方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testHarvestReminderNeverSentBeforeButNowTooEarly

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void testHarvestReminderNeverSentBeforeButNowTooEarly() {
    try {
        createHarvest(HarvestReportRequired.REQUIRED, AuthorIsRegistered.REGISTERED);

        persistInNewTransaction();

        runInTransaction(() -> {
            DateTime fakeNow = getTestStartTime().plus(HarvestReportReminderFeature.FIRST_REMINDER_DELAY).minusSeconds(1);
            DateTimeUtils.setCurrentMillisFixed(fakeNow.getMillis());

            Map<Long, Set<String>> res = harvestReportReminder.sendReminders();

            assertEquals(0, res.size());
        });

    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:21,代碼來源:HarvestReportReminderTest.java

示例2: testHarvestReminderNeverSentBeforeNowOldEnough

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void testHarvestReminderNeverSentBeforeNowOldEnough() {
    try {
        final Harvest harvest = createHarvest(HarvestReportRequired.REQUIRED, AuthorIsRegistered.REGISTERED);

        persistInNewTransaction();

        final DateTime fakeNow = getTestStartTime().plus(HarvestReportReminderFeature.FIRST_REMINDER_DELAY).plusSeconds(1);
        DateTimeUtils.setCurrentMillisFixed(fakeNow.getMillis());

        runInTransaction(() -> {
            final Map<Long, Set<String>> res = harvestReportReminder.sendReminders();

            assertEquals(1, res.size());
            assertThat(res, hasKey(harvest.getId()));
        });

        runInTransaction(() -> {
            final DateTime reminderSentTime = harvestRepository.getOne(harvest.getId()).getEmailReminderSentTime();
            assertEquals(fakeNow, reminderSentTime);
        });

    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:27,代碼來源:HarvestReportReminderTest.java

示例3: testUpdateOnlyThoseWhichEmailIsSent

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void testUpdateOnlyThoseWhichEmailIsSent() {
    try {
        final Harvest harvest = createHarvest(HarvestReportRequired.REQUIRED, AuthorIsRegistered.REGISTERED);
        final Harvest harvest2 = createHarvest(HarvestReportRequired.REQUIRED, AuthorIsRegistered.NOT_REGISTERED);

        persistInNewTransaction();

        final DateTime fakeNow = getTestStartTime().plus(HarvestReportReminderFeature.FIRST_REMINDER_DELAY).plusSeconds(1);
        DateTimeUtils.setCurrentMillisFixed(fakeNow.getMillis());

        runInTransaction(() -> {
            final Map<Long, Set<String>> res = harvestReportReminder.sendReminders();

            assertEquals(1, res.size());
            assertThat(res, hasKey(harvest.getId()));
        });

        runInTransaction(() -> assertNull(harvestRepository.getOne(harvest2.getId()).getEmailReminderSentTime()));

    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:25,代碼來源:HarvestReportReminderTest.java

示例4: shouldAddExpenseAndNotify

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void shouldAddExpenseAndNotify() throws Exception {
  DateTimeUtils.setCurrentMillisFixed(new DateTime("2015-09-06").getMillis());
  when(view.getAmount()).thenReturn("123");
  when(view.getType()).thenReturn("Food");

  ArgumentCaptor<Expense> expenseCaptor = ArgumentCaptor.forClass(Expense.class);

  assertTrue(presenter.addExpense());
  verify(database).addExpense(expenseCaptor.capture());

  Expense actualExpense = expenseCaptor.getValue();
  assertThat(actualExpense.getAmount(), is(123l));
  assertThat(actualExpense.getType(), is("Food"));
  assertThat(actualExpense.getDate(), is("06-09-2015"));
  DateTimeUtils.setCurrentMillisSystem();
}
 
開發者ID:ajitsing,項目名稱:ExpenseManager,代碼行數:18,代碼來源:ExpensePresenterTest.java

示例5: setReceivedAtWithSystemTimeInUTC

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void setReceivedAtWithSystemTimeInUTC() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    final BatchItem batch = TestUtils.createBatchItem(event);

    assertThat(event.getJSONObject("metadata").optString("received_at"), isEmptyString());

    try {
        DateTimeUtils.setCurrentMillisFixed(0);
        strategy.enrich(batch, eventType);
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }

    assertThat(batch.getEvent().getJSONObject("metadata").getString("received_at"),
            equalTo("1970-01-01T00:00:00.000Z"));
}
 
開發者ID:zalando,項目名稱:nakadi,代碼行數:19,代碼來源:MetadataEnrichmentStrategyTest.java

示例6: testLhSyncTimeIsUpdated

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void testLhSyncTimeIsUpdated() {
    try {
        createIntegration(null);
        final SystemUser admin = createNewAdmin();
        persistInNewTransaction();

        authenticate(admin);

        DateTime fakeNow = new DateTime(2014, 6, 25, 12, 34, 0);
        DateTimeUtils.setCurrentMillisFixed(fakeNow.getMillis());
        new LupahallintaHarvestPermitImporter(importFeature, createMockClient(header()), createMockMailHandler())
                .doImport();

        DateTime newFakeNow = fakeNow.plusMinutes(11);
        DateTimeUtils.setCurrentMillisFixed(newFakeNow.getMillis());
        LupahallintaHttpClient mockClient = createMockClient(header());
        new LupahallintaHarvestPermitImporter(importFeature, mockClient, createMockMailHandler())
                .doImport();

        ArgumentCaptor<DateTime> argument = ArgumentCaptor.forClass(DateTime.class);
        verify(mockClient).getPermits(argument.capture());
        assertEquals(fakeNow, argument.getValue());
        assertEquals(newFakeNow, importFeature.getLastLhSyncTime());
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:29,代碼來源:LupahallintaHarvestPermitImporterTest.java

示例7: runBackInTime

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
private static <T> T runBackInTime(DateTime when, Supplier<T> cmd) {
    try {
        DateTimeUtils.setCurrentMillisFixed(when.getMillis());
        return cmd.get();
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:9,代碼來源:HuntingLeaderFinderServiceTest.java

示例8: testHarvestReminderIsSentButNowOldEnough

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void testHarvestReminderIsSentButNowOldEnough() {
    try {
        final Harvest harvest = createHarvest(HarvestReportRequired.REQUIRED, AuthorIsRegistered.REGISTERED);
        harvest.setEmailReminderSentTime(getTestStartTime());

        persistInNewTransaction();

        final DateTime fakeNow = getTestStartTime().plus(HarvestReportReminderFeature.REMINDER_INTERVAL).plusSeconds(1);
        DateTimeUtils.setCurrentMillisFixed(fakeNow.getMillis());

        runInTransaction(() -> {
            final Map<Long, Set<String>> res = harvestReportReminder.sendReminders();

            assertEquals(1, res.size());
            assertThat(res, hasKey(harvest.getId()));
        });

        runInTransaction(() -> {
            final DateTime reminderSentTime = harvestRepository.getOne(harvest.getId()).getEmailReminderSentTime();
            assertEquals(fakeNow, reminderSentTime);
        });

    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:28,代碼來源:HarvestReportReminderTest.java

示例9: tearDown

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Override
protected void tearDown() throws Exception {
    super.tearDown();

    // Restore to normal "now" time
    DateTimeUtils.setCurrentMillisSystem();
    DateTimeZone.setDefault(mOldDefaultJodaTz);
    TimeZone.setDefault(mOldDefaultSystemTz);
    ContentResolver cr = getInstrumentation().getContext().getContentResolver();
    Settings.System.putString(cr, Settings.System.TIME_12_24, mOldTime1224Setting);
}
 
開發者ID:BenAlderfer,項目名稱:RIT-Dining-Planner-Android,代碼行數:12,代碼來源:TestDateUtils.java

示例10: dateArithmetic

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void dateArithmetic() {
    final InstantMillisProvider clock = new InstantMillisProvider(GRAYLOG_EPOCH);
    DateTimeUtils.setCurrentMillisProvider(clock);
    try {
        final Rule rule = parseRuleWithOptionalCodegen();
        final Message message = evaluateRule(rule);
        assertNotNull(message);
        assertTrue(actionsTriggered.get());
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }

}
 
開發者ID:Graylog2,項目名稱:graylog-plugin-pipeline-processor,代碼行數:15,代碼來源:PipelineRuleParserTest.java

示例11: dates

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void dates() {
    final InstantMillisProvider clock = new InstantMillisProvider(GRAYLOG_EPOCH);
    DateTimeUtils.setCurrentMillisProvider(clock);

    try {
        final Rule rule;
        try {
            rule = parser.parseRule(ruleForTest(), false);
        } catch (ParseException e) {
            fail("Should not fail to parse", e);
            return;
        }
        final Message message = evaluateRule(rule);

        assertThat(actionsTriggered.get()).isTrue();
        assertThat(message).isNotNull();
        assertThat(message).isNotEmpty();
        assertThat(message.hasField("year")).isTrue();
        assertThat(message.getField("year")).isEqualTo(2010);
        assertThat(message.getField("timezone")).isEqualTo("UTC");

        // Date parsing locales
        assertThat(message.getField("german_year")).isEqualTo(1983);
        assertThat(message.getField("german_month")).isEqualTo(7);
        assertThat(message.getField("german_day")).isEqualTo(24);
        assertThat(message.getField("english_year")).isEqualTo(1983);
        assertThat(message.getField("english_month")).isEqualTo(7);
        assertThat(message.getField("english_day")).isEqualTo(24);
        assertThat(message.getField("french_year")).isEqualTo(1983);
        assertThat(message.getField("french_month")).isEqualTo(7);
        assertThat(message.getField("french_day")).isEqualTo(24);

    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
 
開發者ID:Graylog2,項目名稱:graylog-plugin-pipeline-processor,代碼行數:38,代碼來源:FunctionsSnippetsTest.java

示例12: timezones

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void timezones() {
    final InstantMillisProvider clock = new InstantMillisProvider(GRAYLOG_EPOCH);
    DateTimeUtils.setCurrentMillisProvider(clock);
    try {
        final Rule rule = parser.parseRule(ruleForTest(), true);
        evaluateRule(rule);

        assertThat(actionsTriggered.get()).isTrue();
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
 
開發者ID:Graylog2,項目名稱:graylog-plugin-pipeline-processor,代碼行數:14,代碼來源:FunctionsSnippetsTest.java

示例13: dateArithmetic

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void dateArithmetic() {
    final InstantMillisProvider clock = new InstantMillisProvider(GRAYLOG_EPOCH);
    DateTimeUtils.setCurrentMillisProvider(clock);
    try {
        final Rule rule = parser.parseRule(ruleForTest(), true);
        final Message message = evaluateRule(rule);

        assertThat(actionsTriggered.get()).isTrue();
        assertThat(message).isNotNull();
        assertThat(message.getField("interval"))
                .isInstanceOf(Duration.class)
                .matches(o -> ((Duration)o).isEqual(Duration.standardDays(1)), "Exactly one day difference");
        assertThat(message.getField("years")).isEqualTo(Period.years(2));
        assertThat(message.getField("months")).isEqualTo(Period.months(2));
        assertThat(message.getField("weeks")).isEqualTo(Period.weeks(2));
        assertThat(message.getField("days")).isEqualTo(Period.days(2));
        assertThat(message.getField("hours")).isEqualTo(Period.hours(2));
        assertThat(message.getField("minutes")).isEqualTo(Period.minutes(2));
        assertThat(message.getField("seconds")).isEqualTo(Period.seconds(2));
        assertThat(message.getField("millis")).isEqualTo(Period.millis(2));
        assertThat(message.getField("period")).isEqualTo(Period.parse("P1YT1M"));


        assertThat(message.getFieldAs(DateTime.class, "long_time_ago")).matches(date -> date.plus(Period.years(10000)).equals(GRAYLOG_EPOCH));

        assertThat(message.getTimestamp()).isEqualTo(GRAYLOG_EPOCH.plusHours(1));
    } finally {
        DateTimeUtils.setCurrentMillisSystem();
    }
}
 
開發者ID:Graylog2,項目名稱:graylog-plugin-pipeline-processor,代碼行數:32,代碼來源:FunctionsSnippetsTest.java

示例14: testPurgeSnapshots

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@Test
public void testPurgeSnapshots() throws IOException {

  Properties properties = new Properties();
  properties.setProperty(Trash.SNAPSHOT_CLEANUP_POLICY_CLASS_KEY, TestCleanupPolicy.class.getCanonicalName());

  TrashTestBase trash = new TrashTestBase(properties);

  DateTimeUtils.setCurrentMillisFixed(new DateTime(2015, 7, 15, 10, 0).withZone(DateTimeZone.UTC).getMillis());

  final List<Path> deletedPaths = Lists.newArrayList();

  Path snapshot1 = new Path(trash.trash.getTrashLocation(), Trash.TRASH_SNAPSHOT_NAME_FORMATTER.print(new DateTime()));
  Path snapshot2 = new Path(trash.trash.getTrashLocation(),
      Trash.TRASH_SNAPSHOT_NAME_FORMATTER.print(new DateTime().minusDays(1)));

  when(trash.fs.listStatus(any(Path.class), any(PathFilter.class))).
      thenReturn(
          Lists.newArrayList(
              new FileStatus(0, true, 0, 0, 0, snapshot1),
              new FileStatus(0, true, 0, 0, 0, snapshot2))
              .toArray(new FileStatus[]{}));
  when(trash.fs.delete(any(Path.class), anyBoolean())).thenAnswer(new Answer<Boolean>() {
    @Override
    public Boolean answer(InvocationOnMock invocation)
        throws Throwable {
      deletedPaths.add((Path) invocation.getArguments()[0]);
      return true;
    }
  });

  trash.trash.purgeTrashSnapshots();

  Assert.assertEquals(deletedPaths.size(), 1);
  Assert.assertTrue(deletedPaths.get(0).equals(snapshot2));

  DateTimeUtils.setCurrentMillisSystem();

}
 
開發者ID:Hanmourang,項目名稱:Gobblin,代碼行數:40,代碼來源:TrashTest.java

示例15: tearDown

import org.joda.time.DateTimeUtils; //導入方法依賴的package包/類
@After
public void tearDown() throws Exception {
    super.tearDown();

    recoveriesDataService.deleteAll();
    usersDataService.deleteAll();

    // Stop faking time
    DateTimeUtils.setCurrentMillisSystem();
}
 
開發者ID:motech,項目名稱:motech,代碼行數:11,代碼來源:PasswordRecoveryServiceBundleIT.java


注:本文中的org.joda.time.DateTimeUtils.setCurrentMillisSystem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。