Time-Human-1.03/0000700000202100001440000000000010551315015013111 5ustar jhoblittusersTime-Human-1.03/MANIFEST0000644000202100001440000000017510551315015014257 0ustar jhoblittusersChanges Human.pm MANIFEST Makefile.PL test.pl META.yml Module meta-data (added by MakeMaker) Time-Human-1.03/test.pl0000644000202100001440000000122010551306073014436 0ustar jhoblittusers# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..1\n"; } END {print "not ok 1\n" unless $loaded;} use Time::Human; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): Time-Human-1.03/Changes0000644000202100001440000000045310551312422014417 0ustar jhoblittusersRevision history for Perl extension Time::Human. 1.03 Wed Jan 10 15:38:11 HST 2007 - applied a one line to trim whitespace in the output, from Ricardo SIGNES - misc. doc cleanups 0.01 Thu Mar 1 21:27:47 2001 - original version; created by h2xs 1.20 with options -XA -n Time::Human Time-Human-1.03/Makefile.PL0000644000202100001440000000044010551306073015077 0ustar jhoblittusersuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( 'NAME' => 'Time::Human', 'VERSION_FROM' => 'Human.pm', # finds $VERSION 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1 ); Time-Human-1.03/Human.pm0000644000202100001440000001136210551312277014543 0ustar jhoblittuserspackage Time::Human; require 5.005_62; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use Time::Human ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( humantime ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( humanize ); our $VERSION = '1.03'; our %templates = ( English => { numbers => [ qw(one two three four five six seven eight nine ten eleven twelve) ], vagueness=> [ "exactly", "just after", "a little after", "coming up to", "almost"], daytime => [ "in the morning", "in the afternoon", "in the evening", "at night" ], minutes => ["five past", "ten past", "quarter past", "twenty past", "twenty-five past", "half past", "twenty-five to", "twenty to", "quarter to", "ten to", "five to"], oclock => "o'clock", midnight => "midnight", midday => "midday", format => "%v %m %h %d", } ); our $Language = "English"; our $Evening = 18; our $Night = 22; # Preloaded methods go here. sub humanize_base { my ($hour, $minute) = @_[2,1]; my $vague = $minute % 5; my $close_minute = $minute-$vague; my $t = $templates{$Language}; my $say_hour; my $daytime =""; if ($vague > 2) {$close_minute += 5} if ($close_minute >30) { $hour++; $hour %=24; } $close_minute /= 5; $close_minute %= 12; if ($hour ==0) { $say_hour = $t->{midnight}; } elsif ($hour == 12) { $say_hour = $t->{midday}; } else { $say_hour = $t->{numbers}[$hour%12-1]; $daytime = $hour <= 12 ? ($t->{daytime}[0]) : $hour >= $Night ? $t->{daytime}[3] : ($hour >= $Evening ? $t->{daytime}[2] : $t->{daytime}[1]); # Afternoon } if ($close_minute==0) { $say_hour .= " ". $t->{oclock} unless $hour ==0 or $hour == 12; } my $say_min = $close_minute ==0? "" : $t->{minutes}[$close_minute-1]; my $rv = $t->{format}; $rv =~ s/%v/$t->{vagueness}[$vague]/eg; $rv =~ s/%m/$say_min/g; $rv =~ s/%h/$say_hour/g; $rv =~ s/%d/$daytime/g; $rv =~ s/^\s+|(?<=\s)\s|\s+$//g; return $rv; } sub humanize { my @foo = humanize_base(@_); return (shift(@foo)." @foo"); } 1; __END__ # Below is stub documentation for your module. You better edit it! =head1 NAME Time::Human - Convert localtime() format to "speaking clock" time =head1 SYNOPSIS use Time::Human; print "The time is now ", humanize(localtime()); =head1 DESCRIPTION This module provides a "vague" rendering of the time into natural language; it's originally intended for text-to-speech applications and other speech-based interfaces. It's fully internationalised: if you look at the code, you'll see a global variable called C<%Time::Human::templates>, which you can fill in for other languages. If you do multinationalise it, please send me templates for other languages to be added to future releases. You can set the default language via the global variable C<$Time::Human::Language> C<$Time::Human::Evening> and C<$Time::Human::Night> decide the hours at which afternoon turns to evening and evening turns to night in your culture. For instance, Greeks may want evening to start at 11pm; for hackers, evening may start at 3am. =head1 USAGE =head2 Import Parameters This module accepts no arguments to it's C method (actually, it doesn't even have an import C). =head2 Exports This module exports a single I, the C function. =head1 CREDITS Simon Cozens (SIMON) for originally creating this module. Ricardo SIGNES (RJBS) for being inhumanly patient in waiting for me to apply a one line whitespace trimming patch. Everyone at the DateTime C. =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details =head1 AUTHOR Simon Cozens, C =head1 CURRENT MAINTAINER Joshua Hoblitt, C =head1 COPYRIGHT Copyright (C) 2006-2007 Joshua Hoblitt. All rights reserved. Copyright (C) 2001-2002(???) Simon Cozens. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module, or in L and L Pods as supplied with Perl 5.8.1 and later. =head1 SEE ALSO L, L =cut Time-Human-1.03/META.yml0000600000202100001440000000044710551315015014371 0ustar jhoblittusers# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Time-Human version: 1.03 version_from: Human.pm installdirs: site requires: distribution_type: module generated_by: ExtUtils::MakeMaker version 6.30