[Index]

date


Define a Date.

Oddjob's inbuilt conversion allows a date to be specified as text in any of these formats:

yyyy-MM-dd
Just the date.
yyyy-MM-dd HH:mm
The date, hours and minutes.
yyyy-MM-dd HH:mm:ss
The date, hours, minutes and seconds.
yyyy-MM-dd HH:mm:ss.SSS
The date, hours, minutes, seconds and milliseconds.

Because of this a date property of a job can be specified perfectly easily as a value or a property. However there are two situations when this is inadequate:

In either or both of these cases the date type can be used.

This date type can also be used to specify a java Calendar property which Oddjob's inbuilt conversion will currently not do from text.

Since v1.3 The date can also be specified using one of these shortcuts:

NOW
The date and time now.
TODAY
The date as of midnight.
YESTERDAY
The date yesterday at midnight.
TOMORROW
The date tomorrow at midnight.

Property Summary

clock The clock to use if a date shortcut is specified.
date A date in text, if a format is specified it is expected to be in the format provide, otherwise it is expected to be in the default format..
format The format the date is in.
timeZone The time zone the date is for.

Example Summary

Example 1 A simple example of specifying a date.
Example 2 Specifying a date in a different format.
Example 3 Adjusting a date by Time Zone.
Example 4 Date shortcuts.

Property Detail

clock

Configured ByELEMENT
AccessREAD_WRITE
RequiredNo, defaults to the current time clock.

The clock to use if a date shortcut is specified. This is mainly here for tests.

date

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredYes.

A date in text, if a format is specified it is expected to be in the format provide, otherwise it is expected to be in the default format..

format

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

The format the date is in.

timeZone

Configured ByATTRIBUTE
AccessREAD_WRITE
RequiredNo.

The time zone the date is for.


Examples

Example 1

A simple example of specifying a date.

<date date="2009-12-25 12:30"/>

Example 2

Specifying a date in a different format.

<date date="25/12/2009 12:30" format="dd/MM/yyyy HH:mm"/>

Example 3

Adjusting a date by Time Zone.

<sequential>
      <jobs>
        <variables id="vars">
          <xmas>
            <date timeZone="US/Hawaii" date="2009-12-25"/>
          </xmas>
        </variables>
        <echo>Christmas in Hawaii starts at ${vars.xmas}.</echo>
      </jobs>
    </sequential>

Example 4

Date shortcuts.

<oddjob>
  <job>
    <sequential>
      <jobs>
        <variables id="vars">
          <now>
            <date date="NOW"/>
          </now>
          <today>
            <date date="TODAY"/>
          </today>
          <yesterday>
            <date date="YESTERDAY"/>
          </yesterday>
          <tomorrow>
            <date date="TOMORROW"/>
          </tomorrow>
        </variables>
        <echo>Today is ${vars.today}. 
The date/time now is ${vars.now}.
Yesterday was ${vars.yesterday}.
Tomorrow is ${vars.tomorrow}.</echo>
      </jobs>
    </sequential>
  </job>
</oddjob>


(c) R Gordon Ltd 2005 - Present