DateTime::Format::Japanese(3)

NAME
DateTime::Format::Japanese - A Japanese DateTime Formatter

SYNOPSIS
  use DateTime::Format::Japanese;
  my $fmt = DateTime::Format::Japanese->new();

  # or if you want to set options,
  my $fmt = DateTime::Format::Japanese->new(
    number_format         => FORMAT_KANJI,
    year_format           => FORMAT_ERA,
    with_gregorian_marker => 1,
    with_bc_marker        => 1,
    with_ampm_marker      => 1,
    with_day_of_week      => 1,
    input_encoding        => $enc_name,
    output_encoding       => $enc_name
  );

  my $str = $fmt->format_datetime($dt);
  my $dt  = $fmt->parse_datetime("平成１６年１月２７日午前５時３０分");

DESCRIPTION
This module implements a DateTime::Format module that can read Japanese date notations and create a DateTime object, and vice versa.

All formatting methods will return a decoded utf-8 string, unless otherwise specified explicitly via the output_encoding parameter.

All parsing methods expect a decoded utf-8 string, unless otherwise specified explicitly via the input_encoding parameter

METHODS

  new()
This constructor will create a DateTime::Format::Japanese object. You may optionally pass any of the following parameters:

  number_format         - how to format numbers (default: FORMAT_KANJI)
  year_format           - how to format years (default: FORMAT_ERA)
  with_day_of_week      - include day of week (default: 0)
  with_gregorian_marker - use gregorian marker (default: 0)
  with_bc_marker        - use B.C. marker (default: 0)
  with_am_marker        - use A.M/P.M marker (default: 0)
  input_encoding        - encoding of input strings for parsing (default: utf8)
  output_encoding       - encoding of output strings for formatting (default: utf8)

Please note that all of the above parameters only take effect for formatting, and not parsing, except for input_encoding. Parsing is done in a way such that it accepts any of the known formats that this module can produce.

  $fmt->parse_datetime($string)
This function will parse a Japanese date/time string and convert it to a DateTime object. If the parsing is unsuccessful, it will croak.

Note that if you didn't provide a input_encoding parameter, the given string is assumed to be decoded utf-8.

This function should be able to parse almost all of the common Japanese date notations, whether they are written using ascii numerals, double byte numerals, and kanji numerals. The date components (year, month, day or era name, era year, month, day) must be present in the string. The time components are optional.

This method can be called as a class function as well.

  my $dt = DateTime::Format::Japanese->parse_datetime($string);
  # or
  my $fmt = DateTime::Format::Japanese->new();
  my $fmt->parse_datetime($string);

FORMATTING METHODS
All of the following methods accept a single parameter, a DateTime object, and return the appropriate string representation.

  my $dt  = DateTime->now();
  my $fmt = DateTime::Format::Japanese->new(...);
  my $str = $fmt->format_datetime($dt);

  $fmt->format_datetime($dt)
Create a complete string representation of a DateTime object in Japanese.

  $fmt->format_ymd($dt)
Create a string representation of year, month, and date of a DateTime object in Japanese

  $fmt->format_year($dt)
Create a string representation of the year of a DateTime object in Japanese

  $fmt->format_month($dt)
Create a string representation of the month of a DateTime object in Japanese

  $fmt->format_day($dt)
Create a string representation of the day (day of month) of a DateTime object in Japanese

  $fmt->format_day_of_week($dt)
Create a string representation of the day of week of a DateTime object in Japanese

  $fmt->format_time($dt)
Create a string representation of the time (hour, minute, second) of a DateTime object in Japanese

  $fmt->format_hour($dt)
Create a string representation of the hour of a DateTime object in Japanese

  $fmt->format_minute($dt)
Create a string representation of the minute of a DateTime object in Japanese

  $fmt->format_second($dt)
Create a string representation of the second of a DateTime object in Japanese

OPTIONS

  input_encoding()

  output_encoding()
Get/Set the encoding that this module should expect to use.

  number_format()
Get/Set the number formatting option. Possible values are:

FORMAT_ROMAN
    Formats the numbers in plain ascii roman numerals.

FORMAT_KANJI
    Formats numbers in kanji numerals without any unit specifiers.

FORMAT_ZENKAKU
    Formats numbers in zenkaku numerals (double-byte equivalent of roman numerals)

FORMAT_KANJI_WITH_UNIT
    Formats numbers in kanji numerals, with unit specifiers.

  year_format()
Get/Set the year formatting option. Possible values are:

FORMAT_ERA
    Formats the year using the Japanese era notation.

FORMAT_GREGORIAN
    Formats the year using the Gregorian notation

  with_gregorian_marker()
Get/Set the option to include the gregorian calendar marker ("西暦")

  with_bc_marker()
Get/Set the option to include the "B.C." marker instead of a negative year.

  with_ampm_marker()
Get/Set the option to include the AM/PM marker. Implies that the hour notation is swictched to 1-12 from 1-23

  with_day_of_week
Get/Set the option to include day of week.

ENCODING
As of version 0.02, DateTime::Format::Japanese can handle arbitrary Japanese encoding for both input and output.

By default, input_encoding is set to 'Guess' and uses Encode::Guess. However, this method is often not adequate to handle Japanese encodings, as there are many ambiguities between any two encoding. In cases where Encode::Guess could not guess the encoding being used, it will croak and emit an error.

Therefore it is always recommended that you set the input_encoding.

CAVEATS

  Day Of Week
Day of week is accepted in the parsing as the last element, but is never used for generating DateTime objects. That is, if you give a date and an unmatching day of week, your day of week will silently be ignored, and DateTime.pm will handle the actual calculation.

  Kanji Dates With Units
Kanji notations have the following limitations, which were :

Gregorian years may only expressed like this: '二〇〇四', not '二千四'

All other fields may be expressed as either '十四' or '一四'. However, it will only understand up to the 10s, not anything higher. This is because of the limit in the range of the fields.

AUTHOR
(c) 2004-2006 Daisuke Maki <daisuke@endeworks.jp<gt>.

POD ERRORS
Hey! The above document had some coding errors, which are explained below:

Around line 506:
    Non-ASCII character seen before =encoding in '$fmt->parse_datetime("平成１６年１月２７日午前５時３０分");'. Assuming UTF-8