Java Code Examples for org.joda.time.DateTime#now()

The following examples show how to use org.joda.time.DateTime#now() . 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: SchedulerTest.java    From celos with Apache License 2.0 6 votes vote down vote up
/**
 * Make sure no slots have been processed if workflow start time is in the future.
 */
@Test
public void workflowStartTimeTest3() throws Exception {
    WorkflowID wfID1 = new WorkflowID("wf1");
    Schedule sch1 = makeHourlySchedule();
    SchedulingStrategy str1 = makeSerialSchedulingStrategy();
    Trigger tr1 = makeAlwaysTrigger();
    MockExternalService srv1 = new MockExternalService(new MockExternalService.MockExternalStatusRunning());
    int maxRetryCount = 0;
    DateTime currentDT = DateTime.now(DateTimeZone.UTC);
    ScheduledTime startTime = new ScheduledTime(currentDT.plusDays(10));

    Workflow wf1 = new Workflow(wfID1, sch1, str1, tr1, srv1, maxRetryCount, startTime, Workflow.DEFAULT_WAIT_TIMEOUT_SECONDS, emptyWorkflowInfo);

    WorkflowConfiguration cfg = new WorkflowConfiguration();
    cfg.addWorkflow(wf1);

    MemoryStateDatabase db = new MemoryStateDatabase();

    Scheduler sched = new Scheduler(cfg, 7 * 24);
    sched.step(new ScheduledTime(currentDT), mockedConnection);

    Assert.assertEquals(0, connection.size());
}
 
Example 2
Source File: DatabaseBlobStorageTest.java    From mojito with Apache License 2.0 6 votes vote down vote up
@Test
public void testCleanup() {

    DateTime now = DateTime.now();
    MBlob notExperied = new MBlob();
    notExperied.setCreatedDate(now);
    notExperied.setExpireAfterSeconds(1000);
    notExperied = mBlobRepository.save(notExperied);

    MBlob experied = new MBlob();
    experied.setCreatedDate(now.minusDays(1));
    experied.setExpireAfterSeconds(1000);
    experied = mBlobRepository.save(experied);

    databaseBlobStorage.deleteExpired();

    assertNull(mBlobRepository.findOne(experied.getId()));
    assertNotNull(mBlobRepository.findOne(notExperied.getId()));
}
 
Example 3
Source File: QueryBuilderTest.java    From remote-monitoring-services-java with MIT License 6 votes vote down vote up
@Test(timeout = 5000, expected = InvalidInputException.class)
@Category({UnitTest.class})
public void failToGetDocumentsSql_WithInvalidInput() throws Throwable {
    // Arrange
    DateTime from = DateTime.now().minusHours(-1);
    DateTime to = DateTime.now();

    // Assert
    QueryBuilder.getDocumentsSQL(
        "alarms' or '1'='1",
        "bef978d4-54f6-429f-bda5-db2494b833ef",
        "rule.id",
        from,
        "device.msg.received",
        to,
        "device.msg.received",
        "asc",
        "device.msg.received",
        0,
        100,
        new String[]{"chiller-01.0", "chiller-02.0"},
        "deviceId");
}
 
Example 4
Source File: CloudStorageHelper.java    From getting-started-java with Apache License 2.0 6 votes vote down vote up
/**
 * Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
 * environment variable, appending a timestamp to end of the uploaded filename.
 */
@SuppressWarnings("deprecation")
public String uploadFile(Part filePart, final String bucketName) throws IOException {
  DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  String dtString = dt.toString(dtf);
  final String fileName = filePart.getSubmittedFileName() + dtString;

  // the inputstream is closed by default, so we don't need to close it here
  BlobInfo blobInfo =
      storage.create(
          BlobInfo
              .newBuilder(bucketName, fileName)
              // Modify access list to allow all users with link to read file
              .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
              .build(),
          filePart.getInputStream());
  logger.log(
      Level.INFO, "Uploaded file {0} as {1}", new Object[]{
          filePart.getSubmittedFileName(), fileName});
  // return the public download link
  return blobInfo.getMediaLink();
}
 
Example 5
Source File: DomainBaseTest.java    From nomulus with Apache License 2.0 6 votes vote down vote up
@Test
public void testClone_doesNotExtendExpirationForPendingTransfer() {
  // Pending transfers shouldn't affect the expiration time
  DateTime now = DateTime.now(UTC);
  DateTime transferExpirationTime = now.plusDays(1);
  DateTime previousExpiration = now.plusWeeks(2);

  DomainTransferData transferData =
      new DomainTransferData.Builder()
          .setPendingTransferExpirationTime(transferExpirationTime)
          .setTransferStatus(TransferStatus.PENDING)
          .setGainingClientId("TheRegistrar")
          .build();
  domain =
      persistResource(
          domain
              .asBuilder()
              .setRegistrationExpirationTime(previousExpiration)
              .setTransferData(transferData)
              .build());

  assertThat(domain.cloneProjectedAtTime(now).getRegistrationExpirationTime())
      .isEqualTo(previousExpiration);
}
 
Example 6
Source File: MuteServiceImpl.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
private void storeState(ModerationActionRequest request) {
    MuteState state = new MuteState();
    state.setGlobal(request.isGlobal());
    state.setUserId(request.getViolator().getUser().getId());
    state.setGuildId(request.getViolator().getGuild().getIdLong());
    DateTime dateTime = DateTime.now();
    if (request.getDuration() != null) {
        dateTime = dateTime.plus(request.getDuration());
    } else {
        dateTime = dateTime.plusYears(100);
    }
    state.setExpire(dateTime.toDate());
    state.setReason(request.getReason());
    if (request.getChannel() != null) {
        state.setChannelId(request.getChannel().getId());
    }
    muteStateRepository.save(state);
}
 
Example 7
Source File: MgcpCallTerminal.java    From JVoiceXML with GNU Lesser General Public License v2.1 5 votes vote down vote up
public synchronized void bye(final SipServletRequest request) throws IOException 
{
    VNXLog.debug("...the terminal...");
    //
    VNXLog.info("received a bye request :"+SIPUtil.dumpSIPMsgHdr(request));
    final List<State> possibleStates = new ArrayList<State>();
    possibleStates.add(QUEUED);
    possibleStates.add(RINGING);
    possibleStates.add(IN_PROGRESS);
    assertState(possibleStates);
    final SipServletResponse ok = request.createResponse(SipServletResponse.SC_OK);
    try 
    {
        ok.send();
        if(DBCfg.dbUsed==1) DBMng.getInstance().insrSIPMsgs(ok,VAppCfg.SIP_MSG_OUTGOING);
        if (remoteConference != null) {
            remoteConference.removeParticipant(this);
        }
    }
    catch(Exception ex)        
    {
        ExLog.exception(LOGGER, ex);
    }
    finally 
    {
        VNXLog.debug("cleanup the terminal :"+this);
        cleanup();
        setState(COMPLETED);
        dateEnded = DateTime.now();
        fireStatusChanged();
    }
}
 
Example 8
Source File: PvPArenaService.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
private static boolean isPvPArenaAvailable() {
	DateTime now = DateTime.now();
	int hour = now.getHourOfDay();
	int day = now.getDayOfWeek();
	if (day == 6 || day == 7) {
		return hour == 0 || hour == 1 || (hour >= 10 && hour <= 23);
	}
	return hour == 0 || hour == 1 || hour == 12 || hour == 13 || (hour >= 18 && hour <= 23);
}
 
Example 9
Source File: EsDailySnapshotStoreTest.java    From soundwave with Apache License 2.0 5 votes vote down vote up
@Test
public void findDiff() throws Exception {
  EsDailySnapshotInstance inst1 = new EsDailySnapshotInstance();
  EsDailySnapshotInstance inst2 = new EsDailySnapshotInstance();
  Assert.assertEquals(0, inst1.findDiff(inst2).size());
  
  inst1.setName("a");
  Assert.assertTrue(inst1.findDiff(inst2).containsKey("name"));

  inst2.setName("b");
  Assert.assertEquals("b", (String) inst1.findDiff(inst2).get("name")[1]);

  inst1.setName("b");
  DateTime now = DateTime.now();
  inst1.setLaunchTime(now.toDate());
  inst2.setLaunchTime(now.toDate());
  Assert.assertEquals(0, inst1.findDiff(inst2).size());

  inst2.setLaunchTime(now.minus(1).toDate());
  Assert.assertEquals(inst2.getLaunchTime(), inst1.findDiff(inst2).get("launch_time")[1]);

  inst2.setLaunchTime(inst1.getLaunchTime());
  inst1.setServiceMappings(new String[]{"a"});
  inst2.setServiceMappings(new String[]{"a"});
  Assert.assertEquals(0, inst1.findDiff(inst2).size());

  inst2.setServiceMappings(new String[]{"b"});
  Map<String, Object[]> result = inst1.findDiff(inst2);
  Assert.assertEquals(1, result.size());
  Assert.assertTrue(inst1.findDiff(inst2).containsKey("service_mapping"));
}
 
Example 10
Source File: JpaTestRules.java    From nomulus with Apache License 2.0 5 votes vote down vote up
/** Builds a {@link JpaIntegrationTestRule} instance. */
public JpaIntegrationTestRule buildIntegrationTestRule() {
  return new JpaIntegrationTestRule(
      clock == null ? new FakeClock(DateTime.now(UTC)) : clock,
      ImmutableList.copyOf(extraEntityClasses),
      ImmutableMap.copyOf(userProperties));
}
 
Example 11
Source File: LRUCacheTest.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void testLruCacheWithDates() {
  // GIVEN
  DateTime firstDate = DateTime.now();
  DateTime secondDate = firstDate.plusMillis(500);
  // WHEN
  underTest.put("mymessage1", firstDate.toDate().getTime());
  underTest.put("mymessage2", firstDate.toDate().getTime());
  underTest.put("mymessage1", secondDate.toDate().getTime());
  // THEN
  assertEquals((Long) firstDate.toDate().getTime(), underTest.get("mymessage1"));
  assertEquals((Long) firstDate.toDate().getTime(), underTest.get("mymessage2"));
}
 
Example 12
Source File: UpdateAllocationTokensCommandTest.java    From nomulus with Apache License 2.0 5 votes vote down vote up
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 13
Source File: DhisConvenienceTest.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a date.
 *
 * @param day the day of the year.
 * @return a date.
 */
public Date getDay( int day )
{
    DateTime dataTime = DateTime.now();
    dataTime = dataTime.withTimeAtStartOfDay();
    dataTime = dataTime.withDayOfYear( day );

    return dataTime.toDate();
}
 
Example 14
Source File: TripEvent.java    From flink-stream-processing-refarch with Apache License 2.0 5 votes vote down vote up
public TripEvent() {
  pickupLat = 0;
  pickupLon = 0;
  dropoffLat = 0;
  dropoffLon = 0;
  totalAmount = 0;
  pickupDatetime = DateTime.now();
  dropoffDatetime = DateTime.now();
}
 
Example 15
Source File: TaxWebserviceCallResult.java    From batchers with Apache License 2.0 5 votes vote down vote up
public static TaxWebserviceCallResult callSucceeded(TaxCalculation taxCalculation) {
    TaxWebserviceCallResult taxWebserviceCallResult = new TaxWebserviceCallResult();
    taxWebserviceCallResult.taxCalculation = taxCalculation;
    taxWebserviceCallResult.responseStatus = 200;
    taxWebserviceCallResult.callDate = DateTime.now();
    taxWebserviceCallResult.successfulResponse = true;
    return taxWebserviceCallResult;
}
 
Example 16
Source File: IncomingPhoneNumber.java    From JVoiceXML with GNU Lesser General Public License v2.1 4 votes vote down vote up
public IncomingPhoneNumber setStatusCallback(final URI statusCallback) {
return new IncomingPhoneNumber(sid, dateCreated, DateTime.now(), friendlyName, accountSid, phoneNumber, apiVersion, hasVoiceCallerIdLookup,
    voiceUrl, voiceMethod, voiceFallbackUrl, voiceFallbackMethod, statusCallback, statusCallbackMethod, voiceApplicationSid, smsUrl,
    smsMethod, smsFallbackUrl, smsFallbackMethod, smsApplicationSid, uri);
 }
 
Example 17
Source File: Notification.java    From JVoiceXML with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Notification build() {
  final DateTime now = DateTime.now();
  return new Notification(sid, now, now, accountSid, callSid, apiVersion, log, errorCode, moreInfo, messageText,
      messageDate, requestUrl, requestMethod, requestVariables, responseHeaders, responseBody, uri);
}
 
Example 18
Source File: IncomingPhoneNumber.java    From JVoiceXML with GNU Lesser General Public License v2.1 4 votes vote down vote up
public IncomingPhoneNumber setVoiceFallbackUrl(final URI voiceFallbackUrl) {
return new IncomingPhoneNumber(sid, dateCreated, DateTime.now(), friendlyName, accountSid, phoneNumber, apiVersion, hasVoiceCallerIdLookup,
    voiceUrl, voiceMethod, voiceFallbackUrl, voiceFallbackMethod, statusCallback, statusCallbackMethod, voiceApplicationSid, smsUrl,
    smsMethod, smsFallbackUrl, smsFallbackMethod, smsApplicationSid, uri);
 }
 
Example 19
Source File: WeatherFragment.java    From OpenWeatherPlus-Android with Apache License 2.0 4 votes vote down vote up
public void changeTextSize() {
    if (!TextUtils.isEmpty(sunrise) && !TextUtils.isEmpty(sunset) && !TextUtils.isEmpty(moonRise) && !TextUtils.isEmpty(moonSet)) {
        DateTime now = DateTime.now(DateTimeZone.UTC);
        float a = Float.valueOf(tz);
        float minute = a * 60;
        now = now.plusMinutes(((int) minute));
        currentTime = now.toString("HH:mm");
        sunView.setTimes(sunrise, sunset, currentTime);
        moonView.setTimes(moonRise, moonSet, currentTime);
        hasAni = true;
    }

    getWeatherForecast(weatherForecastBean);

    if (!ContentUtil.APP_PRI_TESI.equalsIgnoreCase(ContentUtil.APP_SETTING_TESI)) {
        switch (ContentUtil.APP_PRI_TESI) {
            case "small":
                if ("mid".equalsIgnoreCase(ContentUtil.APP_SETTING_TESI)) {
                    smallMid(textViewList);
                } else if ("large".equalsIgnoreCase(ContentUtil.APP_SETTING_TESI)) {

                    smallLarge(textViewList);
                }
                break;
            case "mid":
                if ("small".equalsIgnoreCase(ContentUtil.APP_SETTING_TESI)) {
                    midSmall(textViewList);
                } else if ("large".equalsIgnoreCase(ContentUtil.APP_SETTING_TESI)) {
                    midLarge(textViewList);
                }
                break;
            case "large":
                if ("small".equalsIgnoreCase(ContentUtil.APP_SETTING_TESI)) {
                    largeSmall(textViewList);
                } else if ("mid".equalsIgnoreCase(ContentUtil.APP_SETTING_TESI)) {
                    largeMid(textViewList);
                }
                break;
        }
    }
}
 
Example 20
Source File: App.java    From jqm with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args)
{
    DateTime d = DateTime.now();
    System.out.println("Date GENERATED: " + d);
}