Skip to content

Commit

Permalink
Added time to dataset name #924
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisala committed Apr 24, 2024
1 parent 2f253c5 commit ab022cc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ class ParatooService {
dataSet.progress = Activity.PLANNED
String dataSetName = buildName(
paratooCollectionId.protocolId,
DateUtil.formatAsDisplayDate(paratooCollectionId.eventTime), project)
DateUtil.formatAsDisplayDateTime(paratooCollectionId.eventTime), project)
dataSet.name = dataSetName

dataSet
Expand Down
6 changes: 6 additions & 0 deletions src/main/groovy/au/org/ala/ecodata/DateUtil.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class DateUtil {

static DateTimeFormatter ISO_DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
static DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd")
static DateTimeFormatter DISPLAY_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd h:mm a")
static Date parse(String dateStr) {
SimpleDateFormat format = new SimpleDateFormat(dateFormat)
return format.parse(dateStr.replace("Z", "+0000"))
Expand All @@ -48,6 +49,11 @@ class DateUtil {
dateTime.format(DATE_FORMATTER)
}

static String formatAsDisplayDateTime(Date date) {
ZonedDateTime dateTime = ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault())
dateTime.format(DISPLAY_DATE_TIME_FORMATTER)
}

/**
* Returns a formatted string representing the financial year a report or activity falls into, based on
* the end date. This method won't necessarily work for start dates as it will subtract a day from the value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ParatooServiceSpec extends MongoSpec implements ServiceUnitTest<ParatooSer
assert dataSet.protocol == collectionId.protocolId
assert dataSet.grantId == "g1"
assert dataSet.progress == 'planned'
assert dataSet.name == "aParatooForm 1 - ${DateUtil.formatAsDisplayDate(collectionId.eventTime)} (Project 1)"
assert dataSet.name == "aParatooForm 1 - ${DateUtil.formatAsDisplayDateTime(collectionId.eventTime)} (Project 1)"

[status: 'ok']
}
Expand Down

0 comments on commit ab022cc

Please sign in to comment.