Java Code Examples for java.time.LocalDateTime#getYear()

The following examples show how to use java.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: DateUtils.java    From archivo with GNU General Public License v3.0 6 votes vote down vote up
public static String formatRecordedOnDateTime(LocalDateTime dateTime) {
    if (dateTime == null) {
        return "";
    }

    StringBuilder sb = new StringBuilder();
    sb.append("Recorded ");

    if (dateTime.getDayOfYear() == today) {
        sb.append("today");
    } else if (dateTime.getDayOfYear() == yesterday) {
        sb.append("yesterday");
    } else if (dateTime.getYear() == currentYear) {
        // Don't include the year for recordings from the current year
        sb.append(dateTime.format(DATE_RECORDED_SHORT_DATE_FORMATTER));
    } else {
        sb.append(dateTime.format(DATE_RECORDED_LONG_DATE_FORMATTER));
    }

    sb.append(" at ");
    sb.append(dateTime.format(DATE_RECORDED_TIME_FORMATTER));

    return sb.toString();
}
 
Example 2
Source File: EventsVerticle.java    From vertx-in-action with MIT License 6 votes vote down vote up
private Flowable<KafkaConsumerRecord<String, JsonObject>> generateActivityUpdate(KafkaConsumerRecord<String, JsonObject> record) {
  String deviceId = record.value().getString("deviceId");
  LocalDateTime now = LocalDateTime.now();
  String key = deviceId + ":" + now.getYear() + "-" + now.getMonth() + "-" + now.getDayOfMonth();
  return pgPool
    .preparedQuery(stepsCountForToday())
    .rxExecute(Tuple.of(deviceId))
    .map(rs -> rs.iterator().next())
    .map(row -> new JsonObject()
      .put("deviceId", deviceId)
      .put("timestamp", row.getTemporal(0).toString())
      .put("stepsCount", row.getLong(1)))
    .flatMap(json -> updateProducer.rxSend(KafkaProducerRecord.create("daily.step.updates", key, json)))
    .map(rs -> record)
    .toFlowable();
}
 
Example 3
Source File: TimeStampMilliAccessor.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private Timestamp getTimestamp(int index, TimeZone tz) {
  if (ac.isNull(index)) {
    return null;
  }

  // The Arrow datetime values are already in UTC, so adjust to the timezone of the calendar passed in to
  // ensure the reported value is correct according to the JDBC spec.
  final LocalDateTime date = LocalDateTime.ofInstant(Instant.ofEpochMilli(ac.get(index)), tz.toZoneId());
  return new Timestamp(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth(),
    date.getHour(), date.getMinute(), date.getSecond(), date.getNano());
}
 
Example 4
Source File: DwShadertoy.java    From PixelFlow with MIT License 5 votes vote down vote up
/**
 * uniform vec4 iDate; // image/buffer/sound, Year, month, day, time in seconds in .xyzw
 */
public void set_iDate(){
  LocalDateTime time = LocalDateTime.now();
  iDate[0] = time.getYear();
  iDate[1] = time.getMonthValue();
  iDate[2] = time.getDayOfMonth();
  iDate[3] = System.currentTimeMillis() / 1000;
}
 
Example 5
Source File: DayDimensionGenerator.java    From data-generator with Apache License 2.0 5 votes vote down vote up
private static List<Map<String, Object>> getDayData(int startYear, int startMonth, int startDay){
    List<Map<String, Object>> data = new ArrayList<>();
    LocalDateTime start = LocalDateTime.of(startYear, startMonth, startDay, 0, 0, 0, 0);
    LocalDateTime end = LocalDateTime.now();
    while(start.isBefore(end)) {
        String date = TimeUtils.toString(start, "yyyy-MM-dd");
        int dayofweek = start.getDayOfWeek().getValue();
        int dayofyear = start.getDayOfYear();
        int weekofyear = ((dayofyear-1) / 7)+1;
        int month = start.getMonth().getValue();
        int dayofmonth = start.getDayOfMonth();
        int quarter = ((month-1) / 3) + 1;
        int year = start.getYear();
        Map<String, Object> map = new HashMap<>();
        map.put("day_str", date+" 00:00:00");
        map.put("dayofweek", dayofweek);
        map.put("dayofyear", dayofyear);
        map.put("weekofyear", weekofyear);
        map.put("month", month);
        map.put("dayofmonth", dayofmonth);
        map.put("quarter", quarter);
        map.put("year", year);
        data.add(map);
        start = start.plusDays(1);
    }
    return data;
}
 
Example 6
Source File: DefaultDateFunctions.java    From jackcess with Apache License 2.0 5 votes vote down vote up
private static int getDayDiff(LocalDateTime ldt1, LocalDateTime ldt2) {
  int y1 = ldt1.getYear();
  int d1 = ldt1.getDayOfYear();
  int y2 = ldt2.getYear();
  int d2 = ldt2.getDayOfYear();
  while(y2  > y1) {
    ldt2 = ldt2.minusYears(1);
    d2 += ldt2.range(ChronoField.DAY_OF_YEAR).getMaximum();
    y2 = ldt2.getYear();
  }
  return d2 - d1;
}
 
Example 7
Source File: ValidateLicAndNotice.java    From systemds with Apache License 2.0 5 votes vote down vote up
/**
	 * This will return if NOTICE file is valid or not.
	 *
	 * @param	noticeFile is the noticew file to be verified.
	 * @return 	Returns if NOTICE file validatation successful or failure.
	 */
	public static boolean validateNotice(String noticeFile) throws Exception {

		boolean bValidNotice = Constants.bSUCCESS;

		LocalDateTime currentTime = LocalDateTime.now();

		String noticeLines[] = new String[2];
		boolean noticeLineIn[] = new boolean[4];

// ToDo: fix notice lines
		noticeLines[0] = "Apache SystemDS";
		noticeLines[1] = "Copyright [2015-" + currentTime.getYear() + "]";

		BufferedReader reader = new BufferedReader(new FileReader(noticeFile));
		String line = null;
		while ((line = reader.readLine()) != null) {
			line = line.trim();

			for (int i = 0; i < noticeLines.length; i++)
				if (line.contains(noticeLines[i]))
					noticeLineIn[i] = true;
		}

		for (int i = 0; i < noticeLines.length; i++) {
			if (!noticeLineIn[i]) {
				bValidNotice = Constants.bFAILURE;
			}
		}

		if(bValidNotice == Constants.bSUCCESS)
			Utility.debugPrint(Constants.DEBUG_INFO2, "Notice validation successful.");

		return bValidNotice;
	}
 
Example 8
Source File: BotLogger.java    From TelegramApi with MIT License 5 votes vote down vote up
private static String dateFormatterForFileName(@NotNull LocalDateTime dateTime) {
    String dateString = "";
    dateString += dateTime.getDayOfMonth();
    dateString += dateTime.getMonthValue();
    dateString += dateTime.getYear();
    return dateString;
}
 
Example 9
Source File: ZipUtils.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static long javaToDosTime(long time) {
    Instant instant = Instant.ofEpochMilli(time);
    LocalDateTime ldt = LocalDateTime.ofInstant(
            instant, ZoneId.systemDefault());
    int year = ldt.getYear() - 1980;
    if (year < 0) {
        return (1 << 21) | (1 << 16);
    }
    return (year << 25 |
        ldt.getMonthValue() << 21 |
        ldt.getDayOfMonth() << 16 |
        ldt.getHour() << 11 |
        ldt.getMinute() << 5 |
        ldt.getSecond() >> 1) & 0xffffffffL;
}
 
Example 10
Source File: EventStatsTest.java    From vertx-in-action with MIT License 5 votes vote down vote up
private KafkaProducerRecord<String, JsonObject> dailyStepsUpdateRecord(String deviceId, long steps) {
  LocalDateTime now = LocalDateTime.now();
  String key = deviceId + ":" + now.getYear() + "-" + now.getMonth() + "-" + now.getDayOfMonth();
  JsonObject json = new JsonObject()
    .put("deviceId", deviceId)
    .put("timestamp", now.toString())
    .put("stepsCount", steps);
  return KafkaProducerRecord.create("daily.step.updates", key, json);
}
 
Example 11
Source File: CongratsTest.java    From vertx-in-action with MIT License 5 votes vote down vote up
private KafkaProducerRecord<String, JsonObject> record(String deviceId, long steps) {
  LocalDateTime now = LocalDateTime.now();
  String key = deviceId + ":" + now.getYear() + "-" + now.getMonth() + "-" + now.getDayOfMonth();
  JsonObject json = new JsonObject()
    .put("deviceId", deviceId)
    .put("timestamp", now.toString())
    .put("stepsCount", steps);
  return KafkaProducerRecord.create("daily.step.updates", key, json);
}
 
Example 12
Source File: BotLogger.java    From TelegramApi with MIT License 5 votes vote down vote up
private static String dateFormatterForLogs(@NotNull LocalDateTime dateTime) {
    String dateString = "[";
    dateString += dateTime.getDayOfMonth() + "_";
    dateString += dateTime.getMonthValue() + "_";
    dateString += dateTime.getYear() + "_";
    dateString += dateTime.getHour() + ":";
    dateString += dateTime.getMinute() + ":";
    dateString += dateTime.getSecond();
    dateString += "] ";
    return dateString;
}
 
Example 13
Source File: FuzzyValues.java    From icure-backend with GNU General Public License v2.0 4 votes vote down vote up
public static long getFuzzyDate(LocalDateTime dateTime, TemporalUnit precision) {
	return dateTime.getYear() * 10000l + (precision == ChronoUnit.YEARS ? 0 : (
			dateTime.getMonthValue() * 100l + (precision == ChronoUnit.MONTHS ? 0 : (
					dateTime.getDayOfMonth()
			))));
}
 
Example 14
Source File: Timestamp.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 15
Source File: DurationTransformer.java    From jpmml-sklearn with GNU Affero General Public License v3.0 3 votes vote down vote up
@Override
public List<Feature> encodeFeatures(List<Feature> features, SkLearnEncoder encoder){
	GregorianCalendar epoch = getEpoch();
	String function = getFunction();

	LocalDateTime epochDateTime = CalendarUtil.toLocalDateTime(epoch);
	if(epochDateTime.getMonthValue() != 1 || epochDateTime.getDayOfMonth() != 1){
		throw new IllegalArgumentException(String.valueOf(epochDateTime));
	}

	int year = epochDateTime.getYear();

	String dateFunction = function;

	if(dateFunction.startsWith("date")){
		dateFunction = dateFunction.substring("date".length(), dateFunction.length());
	}

	dateFunction = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, dateFunction);

	List<Feature> result = new ArrayList<>();

	for(int i = 0; i < features.size(); i++){
		ObjectFeature objectFeature = (ObjectFeature)features.get(i);

		FieldName name = FieldName.create(dateFunction + "(" + (FeatureUtil.getName(objectFeature)).getValue() + ", " + year + ")");

		DerivedField derivedField = encoder.ensureDerivedField(name, OpType.CONTINUOUS, DataType.INTEGER, () -> PMMLUtil.createApply(function, objectFeature.ref(), PMMLUtil.createConstant(year, DataType.INTEGER)));

		result.add(new ContinuousFeature(encoder, derivedField));
	}

	return result;
}
 
Example 16
Source File: Timestamp.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 17
Source File: Timestamp.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 18
Source File: TimeUtil.java    From game-server with MIT License 3 votes vote down vote up
/**
 * 判断两个时间是否在同一周(注意这里周日和周一判断是在一周里的)
 *
 * @param time1
 * @param time2
 * @return
 */
public static boolean isSameWeek(long time1, long time2) {
    LocalDateTime ldt1 = LocalDateTime.ofInstant(Instant.ofEpochMilli(time1), ZoneId.systemDefault());
    LocalDateTime ldt2 = LocalDateTime.ofInstant(Instant.ofEpochMilli(time2), ZoneId.systemDefault());
    TemporalField woy = WeekFields.of(Locale.getDefault()).weekOfWeekBasedYear();
    return ldt1.getYear() == ldt2.getYear() && ldt1.get(woy) == ldt2.get(woy);
}
 
Example 19
Source File: TimeUtil.java    From game-server with MIT License 2 votes vote down vote up
/**@
 * 判断两个时间是否在同一季度
 *
 * @param time1
 * @param time2
 * @return
 */
public static boolean isSameQuarter(long time1, long time2) {
    LocalDateTime ldt1 = LocalDateTime.ofInstant(Instant.ofEpochMilli(time1), ZoneId.systemDefault());
    LocalDateTime ldt2 = LocalDateTime.ofInstant(Instant.ofEpochMilli(time2), ZoneId.systemDefault());
    return ldt1.getYear() == ldt2.getYear() && ldt1.getMonthValue() / 4 == ldt2.getMonthValue() / 4;
}
 
Example 20
Source File: TimeUtil.java    From game-server with MIT License 2 votes vote down vote up
/**@
 * 判断两个时间是否在同一月
 *
 * @param time1
 * @param time2
 * @return
 */
public static boolean isSameMonth(long time1, long time2) {
    LocalDateTime ldt1 = LocalDateTime.ofInstant(Instant.ofEpochMilli(time1), ZoneId.systemDefault());
    LocalDateTime ldt2 = LocalDateTime.ofInstant(Instant.ofEpochMilli(time2), ZoneId.systemDefault());
    return ldt1.getYear() == ldt2.getYear() && ldt1.getMonthValue() == ldt2.getMonthValue();
}