GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
DateTime::Format::Japanese(3) User Contributed Perl Documentation DateTime::Format::Japanese(3)

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

  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("平成16年1月27日午前5時30分");

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

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.

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);

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);

Create a complete string representation of a DateTime object in Japanese.

Create a string representation of year, month, and date of a DateTime object in Japanese

Create a string representation of the year of a DateTime object in Japanese

Create a string representation of the month of a DateTime object in Japanese

Create a string representation of the day (day of month) of a DateTime object in Japanese

Create a string representation of the day of week of a DateTime object in Japanese

Create a string representation of the time (hour, minute, second) of a DateTime object in Japanese

Create a string representation of the hour of a DateTime object in Japanese

Create a string representation of the minute of a DateTime object in Japanese

Create a string representation of the second of a DateTime object in Japanese

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

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.

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

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

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

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

Get/Set the option to include day of week.

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.

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 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.

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

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("平成16年1月27日午前5時30分");'. Assuming UTF-8
2008-08-24 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.