Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #51 from pqrth/iso_8601_date_time
Browse files Browse the repository at this point in the history
Uses ISO 8601 date time format
  • Loading branch information
tedcasey authored Oct 28, 2019
2 parents c537eda + d493b05 commit 5b6c511
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Random;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;

Expand All @@ -60,8 +56,8 @@ public abstract class DataGenerator {
protected static final Logger logger = Logger.getLogger(DataGenerator.class.getName());
protected static final Random randomGen = new Random();
protected static JSONParser parser = new JSONParser();
protected static final String rideDefaultDateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'";
protected static final String jsonFullDateFormat = "yyyy-MM-dd";
private static final DateTimeFormatter ISO_8601_DATE_TIME_FORMATTER = DateTimeFormatter.ISO_INSTANT;
private static final DateTimeFormatter ISO_8601_DATE_FORMATTER = DateTimeFormatter.ISO_ORDINAL_DATE;
protected static final String dataPrepend = "test-";
public static final String genericRegex = "[0-9a-zA-Z.-]{0,62}";
public static final String genericSmallAlphaRegex = "[a-z]{5,10}";
Expand Down Expand Up @@ -99,8 +95,8 @@ public abstract class DataGenerator {
*
* @return String The default standard for date formatting.
*/
public static String getDateFormat() {
return rideDefaultDateFormat;
public static DateTimeFormatter getDateFormat() {
return ISO_8601_DATE_TIME_FORMATTER;
}

/**
Expand All @@ -113,9 +109,8 @@ public static String getDateFormat() {
*/
public static String generateRandomPassedDate(int minNumDaysPassed, int maxNumDaysPassed) {
int diff = generateRandomInt(minNumDaysPassed, maxNumDaysPassed);
LocalDate rndDate = LocalDate.now().minusDays(diff);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(jsonFullDateFormat);
return formatter.format(rndDate);
ZonedDateTime rndDate = ZonedDateTime.now().minusDays(diff);
return ISO_8601_DATE_FORMATTER.format(rndDate);
}

/**
Expand All @@ -126,10 +121,9 @@ public static String generateRandomPassedDate(int minNumDaysPassed, int maxNumDa
* @return String
*/
public static String generateStdDateTime(int daysFromToday) {
Date now = new Date();
Date newDate = DateUtils.addDays(now, daysFromToday);
DateFormat stdDate = new SimpleDateFormat(rideDefaultDateFormat);
return stdDate.format(newDate);
ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime newDateTime = now.plusDays(daysFromToday);
return getDateFormat().format(newDateTime); // ISO 8601 format
}

/**
Expand All @@ -139,9 +133,8 @@ public static String generateStdDateTime(int daysFromToday) {
*/
public static String getTodayJSONFullDateFormat() {

Date now = new Date();
DateFormat fullDate = new SimpleDateFormat(jsonFullDateFormat);
return fullDate.format(now);
ZonedDateTime now = ZonedDateTime.now();
return ISO_8601_DATE_FORMATTER.format(now);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
"entityName": { "type": "string", "pattern": "^[0-9a-zA-Z]{1}[0-9a-zA-Z._-]{0,62}[0-9a-zA-Z]{1}$", "mutable":false, "searchable":true },
"version": { "type": "string", "pattern": "^[0-9]{12,13}$", "mutable":false },
"url": { "type": "string", "format" : "uri" },
"created": { "type": "string", "pattern":"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$", "format": "date-time", "description":"creation time in yyyy-MM-dd'T'HH:mm:ssZ format", "mutable":false, "searchable":true },
"modified": { "type": "string", "pattern":"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$", "format": "date-time", "description":"last modified time in yyyy-MM-dd'T'HH:mm:ssZ format", "mutable":false, "searchable":true },
"published": { "type": "string", "pattern":"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$", "format": "date-time", "description":"last published time in yyyy-MM-dd'T'HH:mm:ssZ format", "searchable":true },
"created": { "type": "string", "format": "date-time", "description":"creation time in yyyy-MM-ddTHH:mm:ssZ format", "mutable":false, "searchable":true },
"modified": { "type": "string", "format": "date-time", "description":"last modified time in yyyy-MM-ddTHH:mm:ssZ format", "mutable":false, "searchable":true },
"published": { "type": "string", "format": "date-time", "description":"last published time in yyyy-MM-ddTHH:mm:ssZ format", "searchable":true },

"_links":
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"entityName": { "type": "string", "pattern": "^[0-9a-zA-Z]{1}[0-9a-zA-Z._-]{0,62}[0-9a-zA-Z]{1}$", "mutable":false, "searchable":true },
"version": { "type": "string", "pattern": "^[0-9]{12,13}$", "mutable":false },
"url": {"type": "string", "format" : "uri", "maxLength": 2048 },
"created": { "type": "string", "pattern":"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$", "format": "date-time", "description":"creation time in yyyy-MM-dd'T'HH:mm:ssZ format", "mutable":false, "searchable":true },
"modified": { "type": "string", "pattern":"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$", "format": "date-time", "description":"last modified time in yyyy-MM-dd'T'HH:mm:ssZ format", "mutable":false, "searchable":true },
"published": { "type": "string", "pattern":"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$", "format": "date-time", "description":"last published time in yyyy-MM-dd'T'HH:mm:ssZ format", "searchable":true },
"created": { "type": "string", "format": "date-time", "description":"creation time in yyyy-MM-ddTHH:mm:ssZ format", "mutable":false, "searchable":true },
"modified": { "type": "string", "format": "date-time", "description":"last modified time in yyyy-MM-ddTHH:mm:ssZ format", "mutable":false, "searchable":true },
"published": { "type": "string", "format": "date-time", "description":"last published time in yyyy-MM-ddTHH:mm:ssZ format", "searchable":true },
"syncdUrl": { "type": "string", "sync" : "{$path:/publicationId}/article/{$path:/entityName};version={$path:/version}" },
"_links":
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,15 @@
"properties": {
"createdOn": {
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$",
"format": "date-time",
"description": "creation time in yyyy-MM-dd'T'HH:mm:ssZ format",
"description": "creation time in yyyy-MM-ddTHH:mm:ssZ format",
"mutable": false,
"searchable": true
},
"modifiedOn": {
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$",
"format": "date-time",
"description": "modification time in yyyy-MM-dd'T'HH:mm:ssZ format",
"description": "modification time in yyyy-MM-ddTHH:mm:ssZ format",
"mutable": false,
"searchable": true
},
Expand Down

0 comments on commit 5b6c511

Please sign in to comment.