Datetime¶
CWL example¶
cwlVersion: v1.2
class: CommandLineTool
label: "Echo Datetime string format"
baseCommand: echo
requirements:
- class: InlineJavascriptRequirement
- class: SchemaDefRequirement
types:
- $import: https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml
inputs:
start_time:
type: https://raw.githubusercontent.com/eoap/schemas/main/string_format.yaml#DateTime
label: "Start Time"
doc: "Start time in ISO 8601 format"
inputBinding:
valueFrom: |
${
// Parse ISO datetime and extract parts
var date = new Date(inputs.start_time.value);
if (isNaN(date.getTime())) {
throw "Invalid ISO 8601 date format for start_time.";
}
var dateParts = [
"Date Breakdown:",
"Year: " + date.getUTCFullYear(),
"Month: " + (date.getUTCMonth() + 1),
"Day: " + date.getUTCDate(),
"Hour: " + date.getUTCHours(),
"Minute: " + date.getUTCMinutes(),
"Second: " + date.getUTCSeconds()
].join(", ");
return dateParts;
}
outputs:
echo_output:
type: stdout
stdout: echo_output.txt
Input example¶
start_time:
class: https://raw.githubusercontent.com/eoap/schemas/main/ogc.yaml#DateTime
value: "2025-06-15T12:34:56Z"
Execute the example¶
Run the example with:
cwltool examples/string-format/datetime.cwl examples/string-format/datetime.yaml
This produces the output:
INFO /opt/hostedtoolcache/Python/3.13.5/x64/bin/cwltool 3.1.20250110105449
INFO Resolved '../examples/string-format/datetime.cwl' to 'file:///home/runner/work/schemas/schemas/examples/string-format/datetime.cwl'
INFO [job datetime.cwl] /tmp/hc5ymtya$ echo \
'Date Breakdown:, Year: 2025, Month: 6, Day: 15, Hour: 12, Minute: 34, Second: 56' > /tmp/hc5ymtya/echo_output.txt
INFO [job datetime.cwl] completed success
INFO Final process status is success
The content of the echo_output.txt
file is:
Date Breakdown:, Year: 2025, Month: 6, Day: 15, Hour: 12, Minute: 34, Second: 56