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

The following examples show how to use org.joda.time.DateTime#minusSeconds() . 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: SuplLppClient.java    From supl-client with Apache License 2.0 6 votes vote down vote up
private DateTime toGloTime(DateTime dateTime) {
  dateTime = dateTime.plus(TimeConstants.GPS_UTC_EPOCHS_OFFSET_MILLIS);
  int countLeapSec1 = getLeapSecond(dateTime);

  // The countLeapSec1 would produce the correct number of leap seconds except for an edge case
  // where a straddle leap second occurs (number of leap seconds now != number of leap seconds
  // after adjusting the time with the computed leap seconds). In such case, we need to add one to
  // the used leap second.
  DateTime gpsDateTimeMinusLeapSec = dateTime.minusSeconds(countLeapSec1);
  int countLeapSec2 = getLeapSecond(gpsDateTimeMinusLeapSec);

  gpsDateTimeMinusLeapSec = (countLeapSec1 == countLeapSec2)
      ? gpsDateTimeMinusLeapSec
      : gpsDateTimeMinusLeapSec.minusSeconds(countLeapSec2);

  gpsDateTimeMinusLeapSec.plusHours(TimeConstants.MOSCOW_UTC_TIME_OFFSET_HOURS);

  return gpsDateTimeMinusLeapSec;
}
 
Example 2
Source File: EventsExportEventsToICal.java    From unitime with Apache License 2.0 6 votes vote down vote up
public ICalendarMeeting(MeetingInterface meeting, Status status) {
	if (meeting.getStartTime() != null) {
		iStart = new DateTime(meeting.getStartTime());
	} else {
		iStart = new DateTime(meeting.getMeetingDate()).plusMinutes((5 * meeting.getStartSlot()) + meeting.getStartOffset());
	}
	if (meeting.getStartTime() != null) {
		iEnd = new DateTime(meeting.getStopTime());
	} else {
		iEnd = new DateTime(meeting.getMeetingDate()).plusMinutes((5 * meeting.getEndSlot()) + meeting.getEndOffset());
	}
	if (iStart.getSecondOfMinute() != 0) iStart = iStart.minusSeconds(iStart.getSecondOfMinute());
	if (iEnd.getSecondOfMinute() != 0) iEnd = iEnd.minusSeconds(iEnd.getSecondOfMinute());
	if (iStart.getMillisOfSecond() != 0) iStart = iStart.minusMillis(iStart.getMillisOfSecond());
	if (iEnd.getMillisOfSecond() != 0) iEnd = iEnd.minusMillis(iEnd.getMillisOfSecond());
	iLocation = meeting.getLocationName(MESSAGES);
	iStatus = (status != null ? status : meeting.isApproved() ? Status.confirmed() : Status.tentative());
}
 
Example 3
Source File: TextUnitSearcherTest.java    From mojito with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatedDate() throws Exception {

    DateTime now = DateTime.now();
    DateTime secondsBefore = now.minusSeconds(2);
    DateTime secondsAfter = now.plusSeconds(2);
    
    TMTestData tmTestData = new TMTestData(testIdWatcher);
    TextUnitSearcherParameters textUnitSearcherParameters = new TextUnitSearcherParameters();
    textUnitSearcherParameters.setRepositoryIds(tmTestData.repository.getId());
    textUnitSearcherParameters.setUsedFilter(UsedFilter.USED);

    List<TextUnitDTO> search = textUnitSearcher.search(textUnitSearcherParameters);
    assertEquals(8, search.size());

    textUnitSearcherParameters.setTmTextUnitCreatedBefore(secondsBefore);
    search = textUnitSearcher.search(textUnitSearcherParameters);
    assertEquals(0, search.size());

    textUnitSearcherParameters.setTmTextUnitCreatedAfter(secondsBefore);
    textUnitSearcherParameters.setTmTextUnitCreatedBefore(null);
    search = textUnitSearcher.search(textUnitSearcherParameters);
    assertEquals(8, search.size());

    textUnitSearcherParameters.setTmTextUnitCreatedAfter(secondsBefore);
    textUnitSearcherParameters.setTmTextUnitCreatedBefore(secondsAfter);
    search = textUnitSearcher.search(textUnitSearcherParameters);
    assertEquals(8, search.size());
    
    textUnitSearcherParameters.setTmTextUnitCreatedAfter(secondsAfter);
    textUnitSearcherParameters.setTmTextUnitCreatedBefore(null);
    search = textUnitSearcher.search(textUnitSearcherParameters);
    assertEquals(0, search.size());
    
}
 
Example 4
Source File: TimelineConverterTest.java    From twittererer with Apache License 2.0 5 votes vote down vote up
@Test
public void fromTweetsMapAgeSeconds() {
    DateTime now = DateTime.now();
    DateTime tenSecondsAgo = now.minusSeconds(10);
    List<Tweet> tweets = new ArrayList<>();
    tweets.add(createTweet(dtf.print(tenSecondsAgo), null, null, null, null));

    List<TimelineItem> results = TimelineConverter.fromTweets(tweets, now);

    assertThat(results.get(0).getCreatedAt(), is(equalTo("10s")));
}
 
Example 5
Source File: Func.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Override
public Object apply() {
    DateTime now = null == dateTime ? DateTime.now() : dateTime;
    if (null != deltaInSeconds) {
        int delta = deltaInSeconds;
        now = delta < 0 ? now.minusSeconds(-1 * delta) : now.plusSeconds(delta);
    }
    return now;
}
 
Example 6
Source File: EventElasticSearchIOTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
private static void createRangeEvents(String tenant, int eventCount, int stepInSeconds) throws Exception {
    Map<String, Object> eventMap;
    DateTime date = new DateTime();
    for (int i=0;i<eventCount; i++) {
        Event event = new Event();
        event.setWhat("1");
        event.setWhen(date.getMillis());
        event.setData("2");
        event.setTags("event");
        eventMap = event.toMap();

        date = date.minusSeconds(stepInSeconds);
        searchIO.insert(tenant, eventMap);
    }
}
 
Example 7
Source File: AugmentBaseDataVisitor.java    From spork with Apache License 2.0 4 votes vote down vote up
Object GetSmallerValue(Object v) {
    byte type = DataType.findType(v);

    if (type == DataType.BAG || type == DataType.TUPLE
            || type == DataType.MAP)
        return null;

    switch (type) {
    case DataType.CHARARRAY:
        String str = (String) v;
        if (str.length() > 0)
            return str.substring(0, str.length() - 1);
        else
            return null;
    case DataType.BYTEARRAY:
        DataByteArray data = (DataByteArray) v;
        if (data.size() > 0)
            return new DataByteArray(data.get(), 0, data.size() - 1);
        else
            return null;
    case DataType.INTEGER:
        return Integer.valueOf((Integer) v - 1);
    case DataType.LONG:
        return Long.valueOf((Long) v - 1);
    case DataType.FLOAT:
        return Float.valueOf((Float) v - 1);
    case DataType.DOUBLE:
        return Double.valueOf((Double) v - 1);
    case DataType.BIGINTEGER:
        return ((BigInteger)v).subtract(BigInteger.ONE);
    case DataType.BIGDECIMAL:
        return ((BigDecimal)v).subtract(BigDecimal.ONE);
    case DataType.DATETIME:
        DateTime dt = (DateTime) v;
        if (dt.getMillisOfSecond() != 0) {
            return dt.minusMillis(1);
        } else if (dt.getSecondOfMinute() != 0) {
            return dt.minusSeconds(1);
        } else if (dt.getMinuteOfHour() != 0) {
            return dt.minusMinutes(1);
        } else if (dt.getHourOfDay() != 0) {
            return dt.minusHours(1);
        } else {
            return dt.minusDays(1);
        }
    default:
        return null;
    }

}
 
Example 8
Source File: DateMinusSeconds.java    From levelup-java-examples with Apache License 2.0 3 votes vote down vote up
@Test
public void subtract_seconds_from_date_in_java_with_joda () {
	
	DateTime newYearsDay = new DateTime(2013, 1, 1, 0, 0, 0, 0);
	DateTime newYearsEve = newYearsDay.minusSeconds(60);

	DateTimeFormatter fmt = DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss z");
	
	logger.info(newYearsDay.toString(fmt));
	logger.info(newYearsEve.toString(fmt));

	assertTrue(newYearsEve.isBefore(newYearsDay));
}