Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow more timezone formats #2320

Merged
merged 7 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jib-gradle-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
### Added

### Changed
- `jib.container.creationTime` now accepts more timezone formats:`Z`,`+HHmm`. ([#2320](https://github.com/GoogleContainerTools/jib/issues/2260))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe Z was already accepted. So, "accepts a timezone format without colon: +HHmm"? And if this improves usability with git, worth nothing that? Like, "This helps use git commit timestamp from git ... or some git timestamp plugin"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, the issue number in issues/2260 is wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: also add a space after ### Changed. I saw we have the same problem in line 15, so can you add a space after ### Added there too?


### Fixed

Expand Down
1 change: 1 addition & 0 deletions jib-maven-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
### Added

### Changed
- `<container><creationTime>` now accepts more timezone formats:`Z`,`+HHmm`. ([#2320](https://github.com/GoogleContainerTools/jib/issues/2260))

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.nio.file.Paths;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -730,9 +731,16 @@ static Instant getCreationTime(String configuredCreationTime, ProjectProperties
return Instant.now();

default:
return DateTimeFormatter.ISO_DATE_TIME.parse(configuredCreationTime, Instant::from);
DateTimeFormatter formatter =
new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ISO_DATE_TIME) // parses isoStrict
// add ability to parse with no ":" in tz
.optionalStart()
.appendOffset("+HHmm", "+0000")
.optionalEnd()
.toFormatter();
return formatter.parse(configuredCreationTime, Instant::from);
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
}

} catch (DateTimeParseException ex) {
throw new InvalidCreationTimeException(configuredCreationTime, configuredCreationTime, ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.cloud.tools.jib.api.RegistryImage;
import com.google.cloud.tools.jib.configuration.BuildContext;
import com.google.cloud.tools.jib.configuration.ImageConfiguration;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Resources;
Expand Down Expand Up @@ -908,11 +909,52 @@ public void testGetCreationTime_useCurrentTimestamp() throws InvalidCreationTime

@Test
public void testGetCreationTime_isoDateTimeValue() throws InvalidCreationTimeException {
Instant time =
PluginConfigurationProcessor.getCreationTime(
"2011-12-03T10:15:30+09:00", projectProperties);
Instant expected = DateTimeFormatter.ISO_DATE_TIME.parse("2011-12-03T01:15:30Z", Instant::from);
Assert.assertEquals(expected, time);
List<String> validTimeStamps =
ImmutableList.of(
"2011-12-03T10:15:30+09:00",
"2011-12-03T10:15:30+09:00[Asia/Tokyo]",
"2011-12-02T16:15:30-09:00",
"2011-12-03T10:15:30+0900",
"2011-12-02T16:15:30-0900",
"2011-12-03T10:15:30+09",
"2011-12-02T16:15:30-09",
"2011-12-03T01:15:30Z");
for (String timeString : validTimeStamps) {
Instant time = PluginConfigurationProcessor.getCreationTime(timeString, projectProperties);
Assert.assertEquals("for " + timeString, expected, time);
}
}

@Test
public void testGetCreationTime_isoDateTimeValueTimeZoneRegionOnlyAllowedForMostStrict8601Mode() {
List<String> invalidTimeStamps =
ImmutableList.of(
"2011-12-03T01:15:30+0900[Asia/Tokyo]", "2011-12-03T01:15:30+09[Asia/Tokyo]");
for (String timeString : invalidTimeStamps) {
try {
PluginConfigurationProcessor.getCreationTime(timeString, projectProperties);
// this is the expected behavior, not specifically designed like this for any reason, feel
// free to change this behavior and update the test
Assert.fail(
"creationTime should fail if region specified when zone not in HH:MM mode - "
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
+ timeString);
} catch (InvalidCreationTimeException ex) {
// pass
}
}
}

@Test
public void testGetCreationTime_isoDateTimeValueRequiresTimeZone() {
try {
PluginConfigurationProcessor.getCreationTime("2011-12-03T01:15:30", projectProperties);
// this is the expected behavior, not specifically designed like this for any reason, feel
// free to change this behavior and update the test
Assert.fail("getCreationTime should fail if timezone not specified");
} catch (InvalidCreationTimeException ex) {
// pass
}
}

@Test
Expand Down