Skip to content

Commit cebad36

Browse files
committed
Make datetime format configurable [ci fast]
Signed-off-by: Paolo Di Tommaso <[email protected]>
1 parent 024b3f2 commit cebad36

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

modules/nextflow/src/main/groovy/nextflow/trace/ReportSummary.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ class ReportSummary {
6464
}
6565
}
6666

67-
68-
6967
/**
7068
* Hold the summary for each series ie. cpu, memory, time, disk reads, disk writes
7169
*/

modules/nf-commons/src/main/nextflow/util/SysHelper.groovy

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import groovy.transform.CompileStatic
2525
import groovy.transform.Memoized
2626
import groovy.transform.PackageScope
2727
import groovy.util.logging.Slf4j
28+
import nextflow.SysEnv
2829
import nextflow.file.FileHelper
2930
/**
3031
* System helper methods
@@ -66,11 +67,18 @@ class SysHelper {
6667
* The formatted date string
6768
*/
6869
static String fmtDate(Date date, TimeZone tz=null) {
69-
def formatter=new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH)
70+
final formatter=new SimpleDateFormat(fmtEnv(), Locale.ENGLISH)
7071
if(tz) formatter.setTimeZone(tz)
7172
formatter.format(date)
7273
}
7374

75+
static private String fmtEnv() {
76+
final result = SysEnv.get('NXF_DATE_FORMAT', DATE_FORMAT)
77+
return result.toLowerCase() == 'iso'
78+
? "yyyy-MM-dd'T'HH:mm:ssXXX"
79+
: result
80+
}
81+
7482
/**
7583
* Read the system uptime as returned by the {@code uptime} Linux tool
7684
*

modules/nf-commons/src/test/nextflow/util/SysHelperTest.groovy

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package nextflow.util
1919
import java.lang.management.ManagementFactory
2020

2121
import com.sun.management.OperatingSystemMXBean
22+
import nextflow.SysEnv
2223
import nextflow.file.FileHelper
2324
import spock.lang.Specification
2425
/**
@@ -74,6 +75,9 @@ class SysHelperTest extends Specification {
7475

7576
def 'should format date string' () {
7677
given:
78+
def env = dateFormat ? [NXF_DATE_FORMAT:dateFormat] : [:]
79+
SysEnv.push(env)
80+
and:
7781
def defLocale = Locale.getDefault(Locale.Category.FORMAT)
7882
def useLocale = new Locale.Builder().setLanguage(locale).build()
7983
Locale.setDefault(Locale.Category.FORMAT, useLocale)
@@ -85,11 +89,18 @@ class SysHelperTest extends Specification {
8589

8690
cleanup:
8791
Locale.setDefault(Locale.Category.FORMAT, defLocale)
92+
SysEnv.pop()
8893

8994
where:
90-
dateInMilis | locale | expected
91-
1470901220000 | 'en' | '11-Aug-2016 09:40 +0200'
92-
1470901220000 | 'es' | '11-Aug-2016 09:40 +0200'
95+
dateInMilis | locale | dateFormat | expected
96+
1470901220000 | 'en' | null | '11-Aug-2016 09:40'
97+
1470901220000 | 'es' | null | '11-Aug-2016 09:40'
98+
and:
99+
1470901220000 | 'en' | 'iso' | '2016-08-11T09:40:20+02:00'
100+
1470901220000 | 'es' | 'iso' | '2016-08-11T09:40:20+02:00'
101+
and:
102+
1470901220000 | 'en' | "yyyy-MM-dd'T'HH:mm:ss.SSS" | '2016-08-11T09:40:20.000'
103+
1470901220000 | 'es' | "yyyy-MM-dd'T'HH:mm:ss.SSS" | '2016-08-11T09:40:20.000'
93104
}
94105

95106
}

0 commit comments

Comments
 (0)