Skip to content

Commit

Permalink
Merge pull request #930 from AtlasOfLivingAustralia/feature/issue928
Browse files Browse the repository at this point in the history
Handle grouping null dates in DateGroup #928
  • Loading branch information
salomon-j authored May 1, 2024
2 parents 6170591 + 9a0ebdc commit 159bc98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class ReportGroups {

static class DateGroup extends SinglePropertyGroupingStrategy {

static final String MISSING_DATE_GROUP_NAME = "Date missing"
static DateTimeFormatter parser = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.default)
DateTimeFormatter dateFormatter
List buckets
Expand Down Expand Up @@ -157,6 +158,10 @@ class ReportGroups {
def group(data) {
def value = propertyAccessor.getPropertyValue(data)

if (!value) {
return MISSING_DATE_GROUP_NAME // Use a special group for null / empty dates.
}

int result = bucketIndex(value)

// we put results with an exact date match into the group where the end date of the bucket matches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public class ReportGroupsSpec extends Specification {
['2014-09-01T00:00:00Z', '2014-10-01T00:00:00Z', '2014-11-01T00:00:00Z'] | '2014-08-13T00:00:00Z' | 'MM-yyyy' | 'Before 09-2014'
['2014-09-01T00:00:00Z', '2014-10-01T00:00:00Z', '2014-11-01T00:00:00Z'] | '2014-11-01T00:00:01Z' | 'MM-yyyy' | 'After 10-2014'
['2014-10-01T00:00:00Z', '2015-01-01T00:00:00Z', '2015-04-01T00:00:00Z'] | '2014-10-13T00:00:00Z' | 'MM-yyyy' | '10-2014 - 12-2014'
['2014-10-01T00:00:00Z', '2015-01-01T00:00:00Z', '2015-04-01T00:00:00Z'] | null | 'MM-yyyy' | 'Date missing'
['2014-10-01T00:00:00Z', '2015-01-01T00:00:00Z', '2015-04-01T00:00:00Z'] | '' | 'MM-yyyy' | 'Date missing'


}
Expand Down

0 comments on commit 159bc98

Please sign in to comment.