Usage

DateCalc is a small stand-alone Java program that provides simple command-line date expression calculations such as

today
yesterday
month(-1).end
date(2006-12-20).month.name

Installation

Requirements

Java Java 5+ (JRE 1.5)

Unpack

Unpack the distribution ZIP to a directory of choice. Only the JAR file is needed for the execution, all dependent libraries are included.

Command-line Usage

Basic Execution

The JAR file is an executable JAR file that can be run with the -jar option of the JVM. The command below will print the date of today.

yes> java -jar datecalc-2.0.jar
2008-02-18 13:08:02

The CLI accepts command-line options as well. Use options --help to show the available options.

yes> java -jar target\datecalc-2.0.jar --help
usage: java -jar datecalc-2.0.jar [options] expr-1 expr-2 ...
DateCalc - version 2.0
 -f,--format <pattern>                Sets the default format.
 -h,--help                            Prints the help info
 -l,--locale <lang/country-code>      Sets the default locale.
 -z,--timezone <timezone-id/offset>   Sets the default timezone.
Example: java -jar datecalc-2.0.jar --locale=it --timezone=PST today.day.end month(-1).day.start.iso

The default settings for the date-time properties are taken from the platform defaults. Usage of one or more of these options affect the root date-time object. For example, setting the locale to another language than the default, changes the string names of month and week-days.

Date Expressions

Add one or more date expression(s) (see Reference Page ) as arguments to the program and each will be evaluted and printed one at each line.

yes> java -jar datecalc-2.0.jar today yesterday.day.end today.day(12) "today.format(d MMMM yyyy)" date(2006-10-03).day.end month(-1).month.end.day.start today.month.name tomorrow.day.name
2008-02-18 13:38:40
2008-02-17 23:59:59
2008-03-01 13:38:40
18 februari 2008
2006-10-03 23:59:59
2008-01-31 00:00:00
februari
tisdag

Programmatic Usage

DateCalc can be used as an ordinary Java library as well. There are two usage approaches: expressions or methods.

Using Expressions

The CLI reads expressions from the command line and feeds them into the parser. The parser can be used programmatically. It should be initialized with a date-time object and can then parse expressions. the returned value is of multi-type and is therefor represented by a a ParseResult object, that contains one single value; either a date-time or an element, or a string or an integer.

DateTime    root   = DateTimeImpl.create();
Parser      parser = new ParserImpl(root);
ParseResult result = parser.parse("date(2006-10-03).day.end");
DateTime    date   = result.getDateTime();

Using Methods

It is also possible to use its methods directly.

DateTime    date   = DateTimeImpl.create("2006-10-03").getDay().getEnd();

See the JavaDocs for a complete listing of the API.