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

The following examples show how to use java.time.LocalDateTime#getMinute() . 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: AbstractTablist.java    From FunnyGuilds with Apache License 2.0 6 votes vote down vote up
@Deprecated
protected String putHeaderFooterVars(String text) {
    String formatted = text;

    LocalDateTime time = LocalDateTime.now();
    int hour = time.getHour();
    int minute = time.getMinute();
    int second = time.getSecond();

    formatted = StringUtils.replace(formatted, "{HOUR}", ChatUtils.appendDigit(hour));
    formatted = StringUtils.replace(formatted, "{MINUTE}", ChatUtils.appendDigit(minute));
    formatted = StringUtils.replace(formatted, "{SECOND}", ChatUtils.appendDigit(second));
    formatted = ChatUtils.colored(formatted);

    return formatted;
}
 
Example 2
Source File: MonitorSchedule.java    From paas with Apache License 2.0 6 votes vote down vote up
/**
 * 保存容器监控日志
 * 从0s开始,每隔5s
 * @author jitwxs
 * @since 2018/7/9 13:44
 */
@Scheduled(cron = "0/5 * * * * ? ")
public void saveContainerMonitorLog() {
    LocalDateTime time = LocalDateTime.now();

    // 获取所有启动的容器列表
    List<UserContainer> containers = containerService.listByStatus(ContainerStatusEnum.RUNNING);
    for(UserContainer container : containers) {
        // 实时监控,粒度:5s
        if(time.getSecond() % 5 == 0) {
            monitorService.setMonitorInfo(container.getId(), 1);
        }
        // 24小时监控,粒度:5分钟
        if(time.getSecond() % 5 == 0) {
            monitorService.setMonitorInfo(container.getId(), 2);
        }
        // 7日监控,粒度:1小时
        if(time.getMinute() == 0 && time.getSecond() == 0) {
            monitorService.setMonitorInfo(container.getId(), 3);
        }
    }
}
 
Example 3
Source File: TimeHelper.java    From teammates with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a copy of the {@link LocalDateTime} adjusted to be compatible with the format output by
 * {@link #parseDateTimeFromSessionsForm}, i.e. either the time is 23:59, or the minute is 0 and the hour is not 0.
 * The date time is first rounded to the nearest hour, then the special case 00:00 is handled.
 * @param ldt The {@link LocalDateTime} to be adjusted for compatibility.
 * @return a copy of {@code ldt} adjusted for compatibility, or null if {@code ldt} is null.
 * @see #parseDateTimeFromSessionsForm
 */
public static LocalDateTime adjustLocalDateTimeForSessionsFormInputs(LocalDateTime ldt) {
    if (ldt == null) {
        return null;
    }
    if (ldt.getMinute() == 0 && ldt.getHour() != 0 || ldt.getMinute() == 59 && ldt.getHour() == 23) {
        return ldt;
    }

    // Round to the nearest hour
    LocalDateTime rounded;
    LocalDateTime floor = ldt.truncatedTo(ChronoUnit.HOURS);
    LocalDateTime ceiling = floor.plusHours(1);
    Duration distanceToCeiling = Duration.between(ldt, ceiling);
    if (distanceToCeiling.compareTo(Duration.ofMinutes(30)) <= 0) {
        rounded = ceiling;
    } else {
        rounded = floor;
    }

    // Adjust 00:00 -> 23:59
    if (rounded.getHour() == 0) {
        return rounded.minusMinutes(1);
    }
    return rounded;
}
 
Example 4
Source File: NodeMgrTools.java    From WeBASE-Node-Manager with Apache License 2.0 5 votes vote down vote up
/**
 * check target time if within time period
 *
 * @param lastTime target time.
 * @param validLength y:year, M:month, d:day of month, h:hour, m:minute, n:forever valid;
 * example1: 1d; example2:n
 */
public static boolean isWithinPeriod(LocalDateTime lastTime, String validLength) {
    log.debug("start isWithinTime. dateTime:{} validLength:{}", lastTime, validLength);
    if ("n".equals(validLength)) {
        return true;
    }
    if (Objects.isNull(lastTime) || StringUtils.isBlank(validLength)
        || validLength.length() < 2) {
        return false;
    }
    // example: 2d (2 day)
    // 2
    String lifeStr = validLength.substring(0, validLength.length() - 1);
    if (!StringUtils.isNumeric(lifeStr)) {
        log.warn("fail isWithinTime");
        throw new RuntimeException("fail isWithinTime. validLength is error");
    }
    int lifeValue = Integer.parseInt(lifeStr);
    // d
    String lifeUnit = validLength.substring(validLength.length() - 1);
    // now is day 2, last time is day 1, 2 - 1 = 1 < 2 true
    // now is day 3, last time is day 1, 3 - 1 = 2 < 2 false, not within
    LocalDateTime now = LocalDateTime.now();
    switch (lifeUnit) {
        case "y":
            return now.getYear() - lastTime.getYear() < lifeValue;
        case "M":
            return now.getMonthValue() - lastTime.getMonthValue() < lifeValue;
        case "d":
            return  now.getDayOfMonth() - lastTime.getDayOfMonth() < lifeValue;
        case "m":
            return now.getMinute() - lastTime.getMinute() < lifeValue;
        default:
            log.warn("fail isWithinTime lifeUnit:{}", lifeUnit);
            return false;
    }
}
 
Example 5
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 6
Source File: Bear.java    From JavaMainRepo with Apache License 2.0 5 votes vote down vote up
@Override
public double getPredisposition() {
	LocalDateTime dt = LocalDateTime.now();
	if (dt.getMinute() % 7 == 0) {
		return 0.5;
	}
	return 0.0;
}
 
Example 7
Source File: PackedLocalDateTime.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
public static long getMillisecondOfDay(long packedLocalDateTime) {
  LocalDateTime localDateTime = PackedLocalDateTime.asLocalDateTime(packedLocalDateTime);
  if (localDateTime == null) {
    throw new IllegalArgumentException("Cannot get millisecond of day for missing value");
  }
  long total = (long) localDateTime.get(ChronoField.MILLI_OF_SECOND);
  total += localDateTime.getSecond() * 1000;
  total += localDateTime.getMinute() * 60 * 1000;
  total += localDateTime.getHour() * 60 * 60 * 1000;
  return total;
}
 
Example 8
Source File: ClockSkin.java    From Enzo with Apache License 2.0 5 votes vote down vote up
private void checkForNight(final LocalDateTime DATE_TIME) {
    int hour   = DATE_TIME.getHour();
    int minute = DATE_TIME.getMinute();
    
    if (0 <= hour && minute >= 0 && hour <= 5 && minute <= 59|| 17 <= hour && minute <= 59 && hour <= 23 && minute <= 59) {
        getSkinnable().setNightMode(true);
    } else {
        getSkinnable().setNightMode(false);
    }
}
 
Example 9
Source File: TimeOfDay.java    From SmartApplianceEnabler with GNU General Public License v2.0 4 votes vote down vote up
public TimeOfDay(LocalDateTime dateTime) {
    hour = dateTime.getHour();
    minute = dateTime.getMinute();
    second = dateTime.getSecond();
}
 
Example 10
Source File: SecurityST.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
@Test
void testCertRenewalInMaintenanceWindow() {
    String secretName = CLUSTER_NAME + "-cluster-ca-cert";
    LocalDateTime maintenanceWindowStart = LocalDateTime.now().withSecond(0);
    long maintenanceWindowDuration = 14;
    maintenanceWindowStart = maintenanceWindowStart.plusMinutes(5);
    long windowStartMin = maintenanceWindowStart.getMinute();
    long windowStopMin = windowStartMin + maintenanceWindowDuration > 59
            ? windowStartMin + maintenanceWindowDuration - 60 : windowStartMin + maintenanceWindowDuration;

    String maintenanceWindowCron = "* " + windowStartMin + "-" + windowStopMin + " * * * ? *";
    LOGGER.info("Maintenance window is: {}", maintenanceWindowCron);
    KafkaResource.kafkaPersistent(CLUSTER_NAME, 3, 1)
            .editSpec()
                .addNewMaintenanceTimeWindow(maintenanceWindowCron)
            .endSpec().done();

    KafkaUser user = KafkaUserResource.tlsUser(CLUSTER_NAME, KafkaUserUtils.generateRandomNameOfKafkaUser()).done();
    String topicName = KafkaTopicUtils.generateRandomNameOfTopic();

    KafkaTopicResource.topic(CLUSTER_NAME, topicName).done();
    KafkaClientsResource.deployKafkaClients(true, CLUSTER_NAME + "-" + Constants.KAFKA_CLIENTS, user).done();

    String defaultKafkaClientsPodName =
            ResourceManager.kubeClient().listPodsByPrefixInName(CLUSTER_NAME + "-" + Constants.KAFKA_CLIENTS).get(0).getMetadata().getName();

    InternalKafkaClient internalKafkaClient = new InternalKafkaClient.Builder()
        .withUsingPodName(defaultKafkaClientsPodName)
        .withTopicName(topicName)
        .withNamespaceName(NAMESPACE)
        .withClusterName(CLUSTER_NAME)
        .withMessageCount(MESSAGE_COUNT)
        .withKafkaUsername(user.getMetadata().getName())
        .build();

    Map<String, String> kafkaPods = StatefulSetUtils.ssSnapshot(kafkaStatefulSetName(CLUSTER_NAME));

    LOGGER.info("Annotate secret {} with secret force-renew annotation", secretName);
    Secret secret = new SecretBuilder(kubeClient().getSecret(secretName))
        .editMetadata()
            .addToAnnotations(Ca.ANNO_STRIMZI_IO_FORCE_RENEW, "true")
        .endMetadata().build();
    kubeClient().patchSecret(secretName, secret);

    LOGGER.info("Wait until maintenance windows starts");
    LocalDateTime finalMaintenanceWindowStart = maintenanceWindowStart;
    TestUtils.waitFor("maintenance window start",
        Constants.GLOBAL_POLL_INTERVAL, Duration.ofMinutes(maintenanceWindowDuration).toMillis() - 10000,
        () -> LocalDateTime.now().isAfter(finalMaintenanceWindowStart));

    LOGGER.info("Maintenance window starts");

    assertThat("Rolling update was performed out of maintenance window!", kafkaPods, is(StatefulSetUtils.ssSnapshot(kafkaStatefulSetName(CLUSTER_NAME))));

    LOGGER.info("Wait until rolling update is triggered during maintenance window");
    StatefulSetUtils.waitTillSsHasRolled(kafkaStatefulSetName(CLUSTER_NAME), 3, kafkaPods);

    assertThat("Rolling update wasn't performed in correct time", LocalDateTime.now().isAfter(maintenanceWindowStart));

    LOGGER.info("Checking consumed messages to pod:{}", defaultKafkaClientsPodName);

    internalKafkaClient.checkProducedAndConsumedMessages(
        internalKafkaClient.sendMessagesTls(),
        internalKafkaClient.receiveMessagesTls()
    );
}
 
Example 11
Source File: TimePrintMillis.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
public TimePrintMillis(LocalDateTime time) {
  super(time.getHour(), time.getMinute(), time.getSecond());
  millisOfSecond = time.get(ChronoField.MILLI_OF_SECOND);
}
 
Example 12
Source File: DefaultDateFunctions.java    From jackcess with Apache License 2.0 4 votes vote down vote up
private static int getMinuteDiff(LocalDateTime ldt1, LocalDateTime ldt2) {
  int m1 = ldt1.getMinute();
  int m2 = ldt2.getMinute();
  int hourDiff = getHourDiff(ldt1, ldt2);
  return (m2 + (60 * hourDiff)) - m1;
}
 
Example 13
Source File: Timestamp.java    From openjdk-jdk9 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 14
Source File: Timestamp.java    From Java8CN with Apache License 2.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: Timestamp.java    From hottub 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 16
Source File: Timestamp.java    From openjdk-jdk8u 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 JDKSourceCode1.8 with MIT License 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: Timestamp.java    From jdk8u60 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 19
Source File: Timestamp.java    From jdk8u-dev-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 20
Source File: Timestamp.java    From jdk1.8-source-analysis with Apache License 2.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());
}