APISonar


org.joda.time.DateTime.now

> org > joda > time > DateTime > now
org APIs joda APIs time APIs DateTime APIs now APIs

Example 1
private void sampleDateTime() {
        List<String> text = new ArrayList<String>();
        DateTime now = DateTime.now();
        text.add("Now: " + now);
        text.add("Now + 30 minutes: " + now.plusMinutes(30));
        text.add("Now + 5 hours: " + now.plusHours(5));
        text.add("Now + 2 days: " + now.plusDays(2));
        addSample("DateTime", text);
    }
Example 2
public void setGetDate() {
    Date now = DateTime.now().toDate();
    underTest.setDate(FOOBAR, now);

    assertThat(underTest.getDate(FOOBAR, now), equalTo(now));
  }
Example 3
public void testFailure_bothTldStateFlags() throws Exception {
    DateTime now = DateTime.now(UTC);
    thrown.expect(IllegalArgumentException.class);
    runCommandForced(
        String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now.plus(1)),
        "--initial_tld_state=GENERAL_AVAILABILITY",
        "xn--q9jyb4c");
  }
Example 4
public boolean markAsDownloaded(final Duration lastDownloadedInterval) {
    DateTime now = DateTime.now();
    if (lastDownloaded == null || lastDownloaded.isBefore(now.minus(lastDownloadedInterval))) {
      lastDownloaded(now);
      return true;
    }
    return false;
  }
Example 5
public void testTimestampAsNative() throws Exception {
        DateTime now = DateTime.now();
        assertThat(convertAsNative(now, EsType.DATE), instanceOf(Timestamp.class));
        assertEquals(now.getMillis(), ((Timestamp) convertAsNative(now, EsType.DATE)).getTime());
    }
Example 6
public void testClone_doNotExtendExpirationOnDeletedDomain() {
    DateTime now = DateTime.now(UTC);
    domain =
        persistResource(
            domain
                .asBuilder()
                .setRegistrationExpirationTime(now.minusDays(1))
                .setDeletionTime(now.minusDays(10))
                .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE, StatusValue.INACTIVE))
                .build());
    assertThat(domain.cloneProjectedAtTime(now).getRegistrationExpirationTime())
        .isEqualTo(now.minusDays(1));
  }
Example 7
public void givenTwoDatesInJodaTime_whenDifferentiating_thenWeGetSix() {
        DateTime now = DateTime.now();
        DateTime sixDaysBehind = now.minusDays(6);

        org.joda.time.Duration duration = new org.joda.time.Duration(now, sixDaysBehind);
        long diff = Math.abs(duration.getStandardDays());

        assertEquals(diff, 6);
    }
Example 8
public List<? extends JpaNifiFeedProcessorStats> findFeedProcessorStatisticsByProcessorId(String feedName, TimeFrame timeFrame) {
        DateTime now = DateTime.now();
        return findFeedProcessorStatisticsByProcessorId(feedName, timeFrame.startTimeRelativeTo(now), now);
    }
Example 9
public void testHello() throws Exception {
    DateTime now = DateTime.now(UTC);
    assertThatCommand("hello.xml", null)
        .atTime(now)
        .hasResponse("greeting.xml", ImmutableMap.of("DATE", now.toString(dateTimeNoMillis())));
  }
Example 10
public void testUpdateStatusTransitions() throws Exception {
    DateTime now = DateTime.now(UTC);
    AllocationToken token = persistResource(builderWithPromo().build());
    runCommandForced(
        "--prefix",
        "token",
        "--token_status_transitions",
        String.format(
            "\"%s=NOT_STARTED,%s=VALID,%s=CANCELLED\"", START_OF_TIME, now.minusDays(1), now));
    token = reloadResource(token);
    assertThat(token.getTokenStatusTransitions().toValueMap())
        .containsExactly(START_OF_TIME, NOT_STARTED, now.minusDays(1), VALID, now, CANCELLED);
  }
Example 11
public void setCreatedTime(AuditedEntity entity) {
        DateTime now = DateTime.now();
        entity.setCreatedTime(now);
        entity.setModifiedTime(now);
    }
Example 12
public void start()
    {
        DateTime now = DateTime.now();
        executionStartTime.compareAndSet(null, now);
        startNanos.compareAndSet(0, System.nanoTime());
        startFullGcCount.compareAndSet(-1, gcMonitor.getMajorGcCount());
        startFullGcTimeNanos.compareAndSet(-1, gcMonitor.getMajorGcTime().roundTo(NANOSECONDS));

        // always update last execution start time
        lastExecutionStartTime.set(now);
    }
Example 13
public void testFromMethodNameTwoPathVariables() throws Exception {
		DateTime now = DateTime.now();
		UriComponents uriComponents = fromMethodName(
				ControllerWithMethods.class, "methodWithTwoPathVariables", 1, now).build();

		assertThat(uriComponents.getPath(), is("/something/1/foo/" + ISODateTimeFormat.date().print(now)));
	}
Example 14
public boolean isValid(Resource resource) {
        // returns true if the resource's id is an even integer
        int id;
        try {
            id = Integer.parseInt(resource.getId());
        } catch (Exception e) {
            return true;
        }
        DateTime now = DateTime.now();
        resource.setExpectedTerminationTime(new Date(now.minusDays(1).getMillis()));
        // Set the resource as notified so it can be cleaned
        // set the notification time at more than 1 day before the termination time
        resource.setNotificationTime(new Date(now.minusDays(4).getMillis()));
        return id % 2 == 0;
    }
Example 15
private WatchExecutionContext createWatchExecutionContext() {
        DateTime now = DateTime.now(DateTimeZone.UTC);
        return mockExecutionContextBuilder("watch1")
                .wid(new Wid(randomAlphaOfLength(5), now))
                .payload(new Payload.Simple())
                .time("watch1", now)
                .metadata(Collections.emptyMap())
                .buildMock();
    }
Example 16
protected void init() throws Exception {
    DateTime now = DateTime.now(UTC);
    for (String line : Files.readAllLines(inputFile, StandardCharsets.UTF_8)) {
      List<String> fields = Splitter.on(',').splitToList(line);
      try {
        stageCreditUpdate(new CreditBalanceUpdate(fields), now);
      } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Cannot parse fields in line: " + line, e);
      }
      System.out.println();
    }
  }
Example 17
public void testGoodFailoverCertificate() throws Exception {
    setClientCertificateHash(CertificateSamples.SAMPLE_CERT2_HASH);
    DateTime now = DateTime.now(UTC);
    persistResource(Registrar.loadByClientId("NewRegistrar").asBuilder()
        .setClientCertificate(CertificateSamples.SAMPLE_CERT, now)
        .setFailoverClientCertificate(CertificateSamples.SAMPLE_CERT2, now)
        .build());
    assertCommandAndResponse("login_valid.xml", "login_response.xml");
  }
Example 18
public void update(String message){
        setMessage(message);
        setDateTime(DateTime.now());
    }
Example 19
public static Comment newComment(long issueId, int newCommentId, String comment) {
        DateTime now = DateTime.now();
        Long id = Long.parseLong(issueId + "0" + newCommentId);
        URI selfUri = URI.create(TEST_JIRA_URL + "/rest/api/latest/issue/" + issueId + "/comment");
        return new Comment(selfUri, comment, null, null, now, null, null, id);
    }
Example 20
private void sampleGetRelativeTimeSpanStringWithPreposition() {
        List<String> text = new ArrayList<String>();
        DateTime now = DateTime.now();
        text.add("Short future: " + DateUtils.getRelativeTimeSpanString(this, now.plusMinutes(25), true));
        text.add("Medium future: " + DateUtils.getRelativeTimeSpanString(this, now.plusHours(5), true));
        text.add("Long future: " + DateUtils.getRelativeTimeSpanString(this, now.plusDays(3), true));
        text.add("Short past: " + DateUtils.getRelativeTimeSpanString(this, now.minusMinutes(25), true));
        text.add("Medium past: " + DateUtils.getRelativeTimeSpanString(this, now.minusHours(5), true));
        text.add("Long past: " + DateUtils.getRelativeTimeSpanString(this, now.minusDays(3), true));
        addSample("DateUtils.getRelativeTimeSpanString() (with preposition)", text);
    }
Example 21
public void test_getCheckpointTime() {
    DateTime now = DateTime.now(UTC);
    CommitLogCheckpoint checkpoint =
        CommitLogCheckpoint.create(now, ImmutableMap.of(1, T1, 2, T2, 3, T3));
    assertThat(checkpoint.getCheckpointTime()).isEqualTo(now);
  }
Example 22
public void completeSection(String section){
        completedSections.add(section);
        lastSectionCompleteTime = DateTime.now();
        calculatePercentComplete();
    }
Example 23
public static X509Certificate generateRandomX509Certificate(KeyPair keyPair) throws NoSuchAlgorithmException, NoSuchProviderException, CertificateEncodingException, SignatureException, InvalidKeyException {
        DateTime now = DateTime.now(DateTimeZone.UTC);
        X500Principal dnName = new X500Principal("CN=ApacheCloudStack");
        X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();
        certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
        certGen.setSubjectDN(dnName);
        certGen.setIssuerDN(dnName);
        certGen.setNotBefore(now.minusDays(1).toDate());
        certGen.setNotAfter(now.plusYears(3).toDate());
        certGen.setPublicKey(keyPair.getPublic());
        certGen.setSignatureAlgorithm("SHA256WithRSAEncryption");
        return certGen.generate(keyPair.getPrivate(), "BC");
    }
Example 24
private static AllocationToken.Builder builderWithPromo() {
    DateTime now = DateTime.now(UTC);
    return new AllocationToken.Builder()
        .setToken("token")
        .setTokenType(UNLIMITED_USE)
        .setTokenStatusTransitions(
            ImmutableSortedMap.<DateTime, TokenStatus>naturalOrder()
                .put(START_OF_TIME, NOT_STARTED)
                .put(now.minusDays(1), VALID)
                .put(now.plusDays(1), ENDED)
                .build());
  }
Example 25
public void testCustomSerializer() {
        Paper.addSerializer(DateTime.class, new JodaDateTimeSerializer());
        DateTime now = DateTime.now(DateTimeZone.UTC);

        Paper.book().write("joda-datetime", now);
        assertEquals(now, Paper.book().read("joda-datetime"));
    }