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::Baby(3) User Contributed Perl Documentation DateTime::Format::Baby(3)

DateTime::Format::Baby - Parse and format baby-style time

  use DateTime::Format::Baby;

  my $Baby = DateTime::Format::Baby->new('en');
  my $dt = $Baby->parse_datetime('The big hand is on the twelve and the little hand is on the six.');

  $Baby->language('fr');

  print $Baby->format_datetime($dt);
  # -> La grande aiguille est sur le douze et la petite aiguille est sur le six

Extended example, with a fancy clockface (seen in Acme::Time::Asparagus).

  use DateTime::Format::Baby;
  my $baby = DateTime::Format::Baby->new(language => 'en',
                                         numbers  => [
                 'Tomato',      'Eggplant',        'Carrot',     'Garlic',
                 'Green Onion', 'Pumpkin',         'Asparagus',  'Onion',
                 'Corn',        'Brussels Sprout', 'Red Pepper', 'Cabbage',
                 ]
              );
  my $dt = DateTime->new(year => 1964, month  => 10, day    => 16,
                         hour =>   17, minute => 36, second =>  0
           );

  print $baby->format_datetime($dt);
  # -> The big hand is on the Asparagus and the little hand is on the Pumpkin

This module understands baby talk in a variety of languages.

This class offers the following methods.
new($language) or new(%hash)

As usual, this class method returns an instance of the class.

The method can receive either a single parameter specifying the language, or a hash with various parameters (note: not a hash reference, a real hash, in other words a list with an even number of elements). The hash may contain the following keys:

  • language

    Two-char code of a language (ISO 639-1) or special cases "Swedish chef" and "warez".

  • numbers

    Array reference containing the twelve numbers on the clockface. Number "1" is in position 0, number "2" is in position 1, until number "12" which is in position 11.

  • format

    The skeleton of the output baby-talk sentence, with %s to mark where the values for the big hand and the little hand will be inserted.

  • big

    The various names for the big hand, in an array reference. The position within the array does not matter.

  • little

    Same thing for the little hand.

  • parse_datetime($string)

    Given baby talk, this method will return a new "DateTime" object.

    For some languages (en, de, es, fr and it) parsing uses a regexp on various synonyms for 'big' and 'little'. For all other languages, the module only understands the same phrase that it would give using format_datetime().

    If given baby talk that it can't parse, this method may either die or get confused. Don't try things like "The big and little hands are on the six and five, respectively."

  • format_datetime($datetime)

    Given a "DateTime" object, this methods returns baby talk. Remember though that babies only understand time (even then, without am/pm)

  • language($language)

    When given a language, this method sets its language appropriately.

    This method returns the current language. (After processing as above)

  • languages()

    This method return a list of known languages.

Support for this module is provided via the datetime@perl.org email list. See <http://lists.perl.org/> for more details.

No known bug, only known issues.

As Abigail said in his module Acme::Time::Baby, the "Baby" part of the module name is a misnomer, because you have to be at least a toddler to read a clockface and describe it in a complete sentence with a correct syntax (even if a simple one). On the other hand, the common phrase is not "toddler talk", but "baby talk". Therefore Acme::Time::Baby keeps its name Acme::Time::Baby and DateTime::Format::Baby keeps its name DateTime::Format::Baby.

Baby talk does not implement years, months, days or even AM/PM. It's more for amusement than anything else.

You may think that a roundtrip like this:

  my $string       = $baby->format_datetime($datetime);
  my $new_datetime = $baby->parse_datetime($string);

should give the same value with a 5-minute fuzz factor. This is not the case for two reasons. As stated above, babies (or toddlers) do not understand the AM/PM factor. So there can be a 12-hour skip in the roundtrip. The second reason is that when the time is a few minutes past the half-hour (say xx:31 or xx:32), the small hand is not on the same number as when the time is exactly on the half-hour. So there is a 1-hour jump forward during such a round-trip.

As already said above, baby talk does not include convoluted sentences as: "The big and little hands are on the six and five, respectively" or "Both hands are on the five".

Rick Measham <rickm@cpan.org> (BigLug on PerlMonks)

Co-maintainer: Jean Forget (JFORGET at cpan dot org)

This code is a DateTime version of Acme::Time::Baby (copyright 2002 by Abigail) with the ability to parse strings added by Rick Measham.

Abigail's original module contained a language list that is plagarised here. See the documentation for Acme::Time::Baby for language acknowledgements.

If you have additional language data for this module, please also pass it on to Abigail. This module is not meant to replace the original. Rather it is a DateTime port of that module.

This program is copyright 2003, 2015, 2016 by Rick Measham and Jean Forget

This program is based on code that is copyright 2002 by Abigail.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Acme::Time::Baby

Acme::Time::Asparagus

datetime@perl.org mailing list

<http://datetime.perl.org/>

2016-01-27 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.