Replace use of Date with OffsetDateTime and Instant in Actuator
Closes gh-10976
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.info;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
@@ -77,8 +77,8 @@ public class BuildProperties extends InfoProperties {
|
||||
* @return the build time
|
||||
* @see #get(String)
|
||||
*/
|
||||
public Date getTime() {
|
||||
return getDate("time");
|
||||
public Instant getTime() {
|
||||
return getInstant("time");
|
||||
}
|
||||
|
||||
private static Properties processEntries(Properties properties) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,7 @@ package org.springframework.boot.info;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
@@ -73,8 +73,8 @@ public class GitProperties extends InfoProperties {
|
||||
* @return the commit time
|
||||
* @see #get(String)
|
||||
*/
|
||||
public Date getCommitTime() {
|
||||
return getDate("commit.time");
|
||||
public Instant getCommitTime() {
|
||||
return getInstant("commit.time");
|
||||
}
|
||||
|
||||
private static Properties processEntries(Properties properties) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.boot.info;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -55,16 +55,16 @@ public class InfoProperties implements Iterable<InfoProperties.Entry> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of the specified property as a {@link Date} or {@code null} if the
|
||||
* value is not a valid {@link Long} representation of an epoch time.
|
||||
* Return the value of the specified property as an {@link Instant} or {@code null} if
|
||||
* the value is not a valid {@link Long} representation of an epoch time.
|
||||
* @param key the key of the property
|
||||
* @return the property value
|
||||
*/
|
||||
public Date getDate(String key) {
|
||||
public Instant getInstant(String key) {
|
||||
String s = get(key);
|
||||
if (s != null) {
|
||||
try {
|
||||
return new Date(Long.parseLong(s));
|
||||
return Instant.ofEpochMilli(Long.parseLong(s));
|
||||
}
|
||||
catch (NumberFormatException ex) {
|
||||
// Not valid epoch time
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,7 +38,7 @@ public class BuildPropertiesTests {
|
||||
assertThat(properties.getVersion()).isEqualTo("0.0.1");
|
||||
assertThat(properties.getTime()).isNotNull();
|
||||
assertThat(properties.get("time")).isEqualTo("1457098593000");
|
||||
assertThat(properties.getTime().getTime()).isEqualTo(1457098593000L);
|
||||
assertThat(properties.getTime().toEpochMilli()).isEqualTo(1457098593000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -53,7 +53,7 @@ public class GitPropertiesTests {
|
||||
createProperties("master", "abcdefg", null, "1457527123"));
|
||||
assertThat(properties.getCommitTime()).isNotNull();
|
||||
assertThat(properties.get("commit.time")).isEqualTo("1457527123000");
|
||||
assertThat(properties.getCommitTime().getTime()).isEqualTo(1457527123000L);
|
||||
assertThat(properties.getCommitTime().toEpochMilli()).isEqualTo(1457527123000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,7 +62,7 @@ public class GitPropertiesTests {
|
||||
createProperties("master", "abcdefg", null, "2016-03-04T14:36:33+0100"));
|
||||
assertThat(properties.getCommitTime()).isNotNull();
|
||||
assertThat(properties.get("commit.time")).isEqualTo("1457098593000");
|
||||
assertThat(properties.getCommitTime().getTime()).isEqualTo(1457098593000L);
|
||||
assertThat(properties.getCommitTime().toEpochMilli()).isEqualTo(1457098593000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user