Skip to content

Commit

Permalink
Merge pull request #1388 from arvindshmicrosoft/use-fastdateformat
Browse files Browse the repository at this point in the history
Replace SimpleDateFormat with FastDateFormat in ExportHelper
  • Loading branch information
eedrummer authored Nov 7, 2023
2 parents 6192ed7 + 4063fbc commit 77f5953
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/main/java/org/mitre/synthea/export/ExportHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.mitre.synthea.export;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
Expand All @@ -13,6 +12,7 @@
import java.util.TimeZone;
import java.util.UUID;

import org.apache.commons.lang3.time.FastDateFormat;
import org.hl7.fhir.dstu3.model.Condition;
import org.mitre.synthea.engine.Components.Attachment;
import org.mitre.synthea.engine.Components.SampledData;
Expand Down Expand Up @@ -162,41 +162,35 @@ public static String getObservationType(Observation observation) {
/**
* Year-Month-Day date format.
*/
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
private static final FastDateFormat DATE_FORMAT = FastDateFormat.getInstance("yyyy-MM-dd");

/**
* Iso8601 date time format.
*/
private static final SimpleDateFormat ISO_DATE_FORMAT = iso();
private static final FastDateFormat ISO_DATE_FORMAT = iso();

/**
* Create a SimpleDateFormat for iso8601.
* Create a FastDateFormat for iso8601.
* @return Iso8601 date time format.
*/
private static final SimpleDateFormat iso() {
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
f.setTimeZone(TimeZone.getTimeZone("UTC"));
private static final FastDateFormat iso() {
FastDateFormat f = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss'Z'",
TimeZone.getTimeZone("UTC"));
return f;
}

/**
* Get a date string in the format YYYY-MM-DD from the given time stamp.
*/
public static String dateFromTimestamp(long time) {
synchronized (DATE_FORMAT) {
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6231579
return DATE_FORMAT.format(new Date(time));
}
return DATE_FORMAT.format(new Date(time));
}

/**
* Get an iso8601 string for the given time stamp.
*/
public static String iso8601Timestamp(long time) {
synchronized (ISO_DATE_FORMAT) {
// http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6231579
return ISO_DATE_FORMAT.format(new Date(time));
}
return ISO_DATE_FORMAT.format(new Date(time));
}

/**
Expand Down

0 comments on commit 77f5953

Please sign in to comment.