Skip to content

Make timestamps ISO compliant #6013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class ReportSummary {
}
}



/**
* Hold the summary for each series ie. cpu, memory, time, disk reads, disk writes
*/
Expand Down
12 changes: 10 additions & 2 deletions modules/nf-commons/src/main/nextflow/util/SysHelper.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import groovy.transform.CompileStatic
import groovy.transform.Memoized
import groovy.transform.PackageScope
import groovy.util.logging.Slf4j
import nextflow.SysEnv
import nextflow.file.FileHelper
/**
* System helper methods
Expand All @@ -37,7 +38,7 @@ class SysHelper {

public static final String DEFAULT_DOCKER_PLATFORM = 'linux/amd64'

private static String DATE_FORMAT = 'dd-MMM-yyyy HH:mm'
private static final String DATE_FORMAT = 'dd-MMM-yyyy HH:mm'

/**
* Given a timestamp as epoch time convert to a string representation
Expand Down Expand Up @@ -66,11 +67,18 @@ class SysHelper {
* The formatted date string
*/
static String fmtDate(Date date, TimeZone tz=null) {
def formatter=new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH)
final formatter=new SimpleDateFormat(fmtEnv(), Locale.ENGLISH)
if(tz) formatter.setTimeZone(tz)
formatter.format(date)
}

static private String fmtEnv() {
final result = SysEnv.get('NXF_DATE_FORMAT', DATE_FORMAT)
return result.toLowerCase() == 'iso'
? "yyyy-MM-dd'T'HH:mm:ssXXX"
: result
}

/**
* Read the system uptime as returned by the {@code uptime} Linux tool
*
Expand Down
17 changes: 14 additions & 3 deletions modules/nf-commons/src/test/nextflow/util/SysHelperTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package nextflow.util
import java.lang.management.ManagementFactory

import com.sun.management.OperatingSystemMXBean
import nextflow.SysEnv
import nextflow.file.FileHelper
import spock.lang.Specification
/**
Expand Down Expand Up @@ -74,6 +75,9 @@ class SysHelperTest extends Specification {

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

cleanup:
Locale.setDefault(Locale.Category.FORMAT, defLocale)
SysEnv.pop()

where:
dateInMilis | locale | expected
1470901220000 | 'en' | '11-Aug-2016 09:40'
1470901220000 | 'es' | '11-Aug-2016 09:40'
dateInMilis | locale | dateFormat | expected
1470901220000 | 'en' | null | '11-Aug-2016 09:40'
1470901220000 | 'es' | null | '11-Aug-2016 09:40'
and:
1470901220000 | 'en' | 'iso' | '2016-08-11T09:40:20+02:00'
1470901220000 | 'es' | 'iso' | '2016-08-11T09:40:20+02:00'
and:
1470901220000 | 'en' | "yyyy-MM-dd'T'HH:mm:ss.SSS" | '2016-08-11T09:40:20.000'
1470901220000 | 'es' | "yyyy-MM-dd'T'HH:mm:ss.SSS" | '2016-08-11T09:40:20.000'
}

}