Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Fixing bug where expiration dates were improperly rendered in the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
mmontgomery-square committed Mar 8, 2023
1 parent 5d72366 commit 4a21270
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cli/src/main/java/keywhiz/cli/Printing.java
Expand Up @@ -17,10 +17,12 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import java.io.IOException;
import java.text.DateFormat;
import java.time.Instant;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -289,13 +291,14 @@ public void printSecretWithDetails(long secretID) {
}
}

private String apiDateToString(ApiDate apiDate) {
return epochSecondToString(apiDate.toEpochSecond() * 1000);
@VisibleForTesting
static String apiDateToString(ApiDate apiDate) {
return epochSecondToString(apiDate.toEpochSecond());
}

private String epochSecondToString(long epochSecond) {
Date d = new Date(epochSecond);
return DateFormat.getDateTimeInstance().format(d);
@VisibleForTesting
static String epochSecondToString(long epochSecond) {
return Instant.ofEpochSecond(epochSecond).toString();
}

public void printAllClients(List<Client> clients) {
Expand Down
20 changes: 20 additions & 0 deletions cli/src/test/java/keywhiz/cli/PrintingTest.java
@@ -0,0 +1,20 @@
package keywhiz.cli;

import keywhiz.api.ApiDate;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class PrintingTest {
@Test
public void apiDateToString() {
String iso8601 = "2024-03-03T00:00:00Z";
ApiDate apiDate = ApiDate.parse(iso8601);
assertEquals(iso8601, Printing.apiDateToString(apiDate));
}

@Test
public void epochSecondToString() {
assertEquals("2024-03-03T00:00:00Z", Printing.epochSecondToString(1709424000L));
}
}

0 comments on commit 4a21270

Please sign in to comment.