Java Code Examples for org.joda.time.LocalDateTime#getYear()

The following examples show how to use org.joda.time.LocalDateTime#getYear() . 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: ScanFile.java    From act with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This function parses the date from a given scan file's name.
 * @return a local date time
 */
public LocalDateTime getDateFromScanFileTitle() throws Exception {
  for (Pair<Pattern, Map<SCAN_NAME_COMPONENT, Integer>> scan : NAME_EXTRACTION_PATTERNS) {
    Pattern p = scan.getLeft();
    Map<SCAN_NAME_COMPONENT, Integer> groupMap = scan.getRight();
    Matcher m = p.matcher(this.fileName);
    if (m.matches() && groupMap.containsKey(SCAN_NAME_COMPONENT.DATE)) {
      DateTimeFormatter formatter = DateTimeFormat.forPattern(DATE_FORMAT);
      LocalDateTime dateTime = LocalDateTime.parse(m.group(groupMap.get(SCAN_NAME_COMPONENT.DATE)), formatter);
      if (dateTime.getYear() < TWENTYN_INCEPTION) {
        throw new RuntimeException("The date parsed from the file name is malformed.");
      }
      return dateTime;
    }
  }

  // We assume a date will appear in every file name format.
  throw new RuntimeException(String.format("Unable to extract date from scan file name: %s", this.fileName));
}
 
Example 2
Source File: MedtronicPumpPlugin.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private Long getLastPumpEntryTime() {
    Long lastPumpEntryTime = SP.getLong(MedtronicConst.Statistics.LastPumpHistoryEntry, 0L);

    try {
        LocalDateTime localDateTime = DateTimeUtil.toLocalDateTime(lastPumpEntryTime);

        if (localDateTime.getYear() != (new GregorianCalendar().get(Calendar.YEAR))) {
            LOG.warn("Saved LastPumpHistoryEntry was invalid. Year was not the same.");
            return 0L;
        }

        return lastPumpEntryTime;

    } catch (Exception ex) {
        LOG.warn("Saved LastPumpHistoryEntry was invalid.");
        return 0L;
    }

}
 
Example 3
Source File: DateTimeUtil.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public static long toATechDate(LocalDateTime ldt) {
    long atechDateTime = 0L;

    atechDateTime += ldt.getYear() * 10000000000L;
    atechDateTime += ldt.getMonthOfYear() * 100000000L;
    atechDateTime += ldt.getDayOfMonth() * 1000000L;
    atechDateTime += ldt.getHourOfDay() * 10000L;
    atechDateTime += ldt.getMinuteOfHour() * 100L;
    atechDateTime += ldt.getSecondOfMinute();

    return atechDateTime;
}
 
Example 4
Source File: SegmentGenerationWithTimeColumnTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Test
public void testMinAllowedValue() {
  long millis = validMinTime; // is in UTC from epoch (19710101)
  DateTime dateTime = new DateTime(millis, DateTimeZone.UTC);
  LocalDateTime localDateTime = dateTime.toLocalDateTime();
  int year = localDateTime.getYear();
  int month = localDateTime.getMonthOfYear();
  int day = localDateTime.getDayOfMonth();
  Assert.assertEquals(year, 1971);
  Assert.assertEquals(month, 1);
  Assert.assertEquals(day, 1);
}
 
Example 5
Source File: SegmentGenerationWithTimeColumnTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private Object getRandomValueForTimeColumn(boolean isSimpleDate, boolean isInvalidDate) {
  long randomMs = validMinTime + (long) (_random.nextDouble() * (startTime - validMinTime));
  Preconditions.checkArgument(TimeUtils.timeValueInValidRange(randomMs), "Value " + randomMs + " out of range");
  long dateColVal = randomMs;
  Object result;
  if (isInvalidDate) {
    result = new Long(new DateTime(2072, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC).getMillis());
    return result;
  } else if (isSimpleDate) {
    DateTime dateTime = new DateTime(randomMs, DateTimeZone.UTC);
    LocalDateTime localDateTime = dateTime.toLocalDateTime();
    int year = localDateTime.getYear();
    int month = localDateTime.getMonthOfYear();
    int day = localDateTime.getDayOfMonth();
    String dateColStr = String.format("%04d%02d%02d", year, month, day);
    dateColVal = Integer.valueOf(dateColStr);
    result = new Integer(Integer.valueOf(dateColStr));
  } else {
    result = new Long(dateColVal);
  }

  if (dateColVal < minTime) {
    minTime = dateColVal;
  }
  if (dateColVal > maxTime) {
    maxTime = dateColVal;
  }
  return result;
}
 
Example 6
Source File: ScheduleOffsetResolver.java    From qmq with Apache License 2.0 4 votes vote down vote up
private static long year(final LocalDateTime localDateTime) {
    return localDateTime.getYear() * 100000000L;
}
 
Example 7
Source File: DateTimeUtil.java    From AndroidAPS with GNU Affero General Public License v3.0 3 votes vote down vote up
public static boolean isSameDay(LocalDateTime ldt1, LocalDateTime ldt2) {

        return (ldt1.getYear() == ldt2.getYear() && //
                ldt1.getMonthOfYear() == ldt2.getMonthOfYear() && //
                ldt1.getDayOfMonth() == ldt2.getDayOfMonth());

    }