Usage

Basic Usage

Create instances of the date or date range parser as follows:
FlexibleDateFormat      dateFormat      = FlexibleDateFormat.getDateInstance();
FlexibleDateRangeFormat dateRangeFormat = FlexibleDateRangeFormat.getDateInstance();
Parse input strings as follows:
Date date = dateFormat.parse("mar/2013");

DateRange dateRange = dateRangeFormat.parse("mar/2013 to aug/2014");
Date from = dateRange.getFrom();
Date to   = dateRange.getTo();
Format dates and date ranges as follows:
Date date = new Date();
DateRange dateRange = new DateRange(new Date(), new Date());

String formattedDate      = dateFormat.format(date);
String formattedDateRange = dateRangeFormat.format(dateRange);

Date Style and Patterns

Date and date range formats can be created using the same familiar approaches as available when using java.text.DateFormat and java.text.SimpleDateFormat.

For example, using date style:
FlexibleDateFormat      dateFormat      = FlexibleDateFormat.getDateInstance(DateFormat.SHORT);
FlexibleDateRangeFormat dateRangeFormat = FlexibleDateRangeFormat.getDateInstance(DateFormat.SHORT);
For example, using specific patterns:
FlexibleDateFormat      dateFormat      = FlexibleDateFormat.getPatternInstance("yyyy-MM-dd");
FlexibleDateRangeFormat dateRangeFormat = FlexibleDateRangeFormat.getPatternInstance("yyyy-MM-dd");

For more information, see the javadoc documentation for the respective format class.

Locales

Tedhi has full support for locales:
FlexibleDateFormat      dateFormat      = FlexibleDateFormat.getDateInstance(new Locale("en", "NZ"));
FlexibleDateRangeFormat dateRangeFormat = FlexibleDateRangeFormat.getDateInstance(new Locale("en", "NZ"));

FlexibleDateFormat      dateFormat      = FlexibleDateFormat.getDateInstance("d-MM-yyyy", new Locale("en", "NZ"));
FlexibleDateRangeFormat dateRangeFormat = FlexibleDateRangeFormat.getDateInstance("d-MM-yyyy", new Locale("en", "NZ"));

Precision and Time-Zone

Tedhi parses dates to millisecond precision:

  • for dates and the start of date ranges, this is always the first instant of the period in the configured time-zone, ie: 00:00:00.000 AM+zzzz
  • for the end of date ranges, this is always the last instant of the period in the configured time-zone, ie: 23:59:59.999 PM+zzzz
    (or 23:59:60.999 PM or 23:59:58.999 due to a leap second)

Tedhi supports the ability to control the time-zone by a configuration on the FlexibleDateFormat or FlexibleDateRangeFormat instance. However, there is no mechanism to specify the time-zone in the input string when parsing.

Time

Tedhi currently has support for all calendar date fields, however it has no support for time components.

There is an open ticket to add this in version 2.0.