Oxford-Calendar-2.10/0002755000175000017500000000000012466473170012540 5ustar domdomOxford-Calendar-2.10/META.json0000644000175000017500000000200712466473164014161 0ustar domdom{ "abstract" : "unknown", "author" : [ "unknown" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142690", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Oxford-Calendar", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Date::Calc" : "0", "Test::Exception" : "0", "Test::More" : "0", "Text::Abbrev" : "0", "Time::Piece" : "0", "Time::Seconds" : "0", "YAML" : "0" } } }, "release_status" : "stable", "version" : "2.10" } Oxford-Calendar-2.10/Changes0000644000175000017500000001075012466473134014034 0ustar domdom2.10 2015-02-10 - Update URLs to University web site - Update calendar from information in http://www.ox.ac.uk/about/facts-and-figures/dates-of-term 2.09 2014-01-08 - Update calendar from information in http://www.ox.ac.uk/about_the_university/university_year/dates_of_term.html (thanks, Stephen Gower; RT#91925) - Correct out of date reference to Computing Services (thanks, Stephen, Gower; RT#91926) 2.08 2013-02-12 - Update calendar from information in http://www.ox.ac.uk/gazette/2012-2013/7february2013-no5014/councilandmaincommittees/#112333 2.07 2012-06-26 - Correct incorrect data for Michaelmas 2017 (RT#78048) 2.06 2012-06-09 - Update calendar from information in http://www.ox.ac.uk/gazette/2011-2012/26january2012-no4976/councilandmaincommittees/#65714 2.05 2011-08-21 - Correct Georgian -> Gregorian in documentation - Improve first example in documentation: use say rather than print; use ToOx in scalar context; explicitly use Date::Calc (fixes RT#66439) (thanks, David Sheldon) - Clarify form of arguments for FromOx (fixes RT#66440) - Switch to Time::Piece for some calculations; fixes bug when calculating Oxford dates out of term near a DST change (RT#64539) 2.04 2010-05-03 - Update calendar from information in http://www.ox.ac.uk/gazette/2009-10/weekly/110310/acts.htm#2Ref - Bugfix: fix incorrect week number from ToOx for Sundays in week 0 or earlier of term (thanks to Tim Bagot for the fix) 2.03 2009-04-26 - Update calendar from information in http://www.ox.ac.uk/gazette/2008-9/weekly/120309/acts.htm#2Ref 2.02 2008-06-05 - Fix POD formatting problems (fixes RT#36481) [thanks to Will Thompson for pointing this out] 2.01 2008-03-21 - Update calendar from information in http://www.ox.ac.uk/gazette/2007-8/weekly/190308/acts.htm#3Ref 2.0 2008-01-16 INCOMPATIBLE CHANGES: - ToOx will return an array if called in array context; this will break code that does 'print ToOx(..)' directly - The string returned by ToOx no longer has a trailing full stop. - ToOx will return undef, rather than an error string if a date requested is not in term time (if full_term or ext_term was specifed) - Parse will return undef, rather than an error string, if the string could not be parsed - ToOx and FromOx will die if the date requested is not in the internal database; if appropriate, you should eval calls to these functions and perform appropriate error handling. - The format of the YAML database has changed. OTHER CHANGES: - Improve documention to describe the Oxford date format and add references to the University (fixes RT#27365) - Move Calendar.pm to lib/, and test.pl to t/ (and convert to using Test::More) - General refactoring and cleanup - Changes from Aaron Wilson: - ToOx can be called in multiple modes with different levels of strictness (fixes RT#27366). - Changes inspired by Janet McKnight: - The module calculates the Oxford terms from the definition laid out in University Regulations as well as the reckoning of dates of full term (also fixes RT#27366). - Reference to CPAN RT in documentation - ToOx can be called with a 'confirmed' option, which ignores dates marked as provisional (fixes RT#31289). 1.8 2007-05-27 - New maintainer: Dominic Hargreaves - Convert built-in data to YAML and add more dates - Support reading data from an external YAML file - Remove support for fetching data from University web pages, as this functionality is fragile and has broken. - Run perltidy on Calendar.pm in line with Damien Conway's Best Practices 1.7 2005-01-04 - Corrected terms 2004-2006 (which were incorrectly given as 2003) - Term dates before 2004 are not shown on the OU website; always pre-load them 1.6 2004-11-20 - New maintainer: Eugene van der Pijll - Added terms 2004-2006 to internal database 2002-11-26 09:06 simon * MANIFEST: Yes, we are a Debian module. 2002-11-26 09:03 simon * Calendar.pm: Keep internal database going for another few years. 2002-06-17 19:21 simon * Calendar.pm: Fix ugly "week 0" bug 2002-05-02 19:27 simon * Calendar.pm, Changes, MANIFEST, Makefile.PL, test.pl, debian/changelog, debian/control, debian/files, debian/rules: Bring calendar under version control. Oxford-Calendar-2.10/SIGNATURE0000644000175000017500000000356412466473170014032 0ustar domdomThis file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.73. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 SHA1 b7bf44d2184d71d642ab401b358f2b6a1eb666d3 Changes SHA1 966eb4ea8f6b610d1bbeda6d89030f9f3f84994b MANIFEST SHA1 790cabf4cab35c1c35f76be0572b542557a5a2f6 META.json SHA1 05d794f6b62b09cb8efd401ddba578beda8d2bae META.yml SHA1 88ab794c78e0bfa7c29ee223eecf4be636aadc95 Makefile.PL SHA1 21ab33da4cae1505a9b80a46c812983fd1e28ccc lib/Oxford/Calendar.pm SHA1 fdb7c340183280dec9155d314067d146f7bcd3df t/00_all.t SHA1 7909082ff0b1bd24a68766335ea9850d95f0b498 t/01_bug_sundays_0th_or_earlier.t SHA1 ec67c2442022354e1c562ba3dc6a79a873e4ab58 t/02_bug_nearest_dst.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCAAGBQJU2nZ0AAoJEMAFfnFNaU+yJd4QAMiVQfI3gH63INSxMYFuDlHk HYmCQyq9p1eMdsFIp5UK7GLAiYVooxN2yiohCelK3HdMlsfRMjPtJem+FbdyPQXi kKixjgSfPNrZAqnJ10uaoEDZL/wY7jw/q4sh8G1EK/Z59lYj5DNSh1Eq76eNYg8v PI9LOrYssOhZ2YdL5vK7oCGVM9/zVxhi4r8WD27qIQeumknQjLzidi3xxpm+KNtP j7RuYRPqM4CqnqoU/SOII3V5XHo+rmPOKI3EI9B5c/WlFA+l7/PB+Ie50Ea1xdPu Rhh/mJG8uNYhEQBLJhQFNI+0L09/XKRPbMrgCwj6sMNyEDVOGcD7GbYpjmSHvTK0 Pz9CoBqmWI9PKKHFCNn7QfRvHO9TLEzrCC6Jaopm8bhQXsxTh0EixyRkw8OZeJrg C24RQgHnIhJI1hrvzwCTTimYgCjaMhGB7FiPTXIOZtHIPZpo8Yx6/SsBxi0aFm3g DUITJyG9xCQ6vglehDVQBuxRZjTH6Q7Z8PHXbnX4FRuxQePIMtWd96KXCKtGHKG2 ih2nFvM5Ce9Xgtn89k7UZohNBTrrwVTYChS048uELBSpGjsIKLKCmDZzMxgq4yPb kMJT+XA2x+XyrQRevsEM90aK7s3xv6pfWPd1fgiUBfB5OBcz7QS0sUq5s6tAijGj JODFco4bCHYMC1/jAdyw =5sdK -----END PGP SIGNATURE----- Oxford-Calendar-2.10/META.yml0000644000175000017500000000106712466473164014016 0ustar domdom--- abstract: unknown author: - unknown build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.98, CPAN::Meta::Converter version 2.142690' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Oxford-Calendar no_index: directory: - t - inc requires: Date::Calc: '0' Test::Exception: '0' Test::More: '0' Text::Abbrev: '0' Time::Piece: '0' Time::Seconds: '0' YAML: '0' version: '2.10' Oxford-Calendar-2.10/MANIFEST0000644000175000017500000000056312466473164013676 0ustar domdomlib/Oxford/Calendar.pm Changes MANIFEST Makefile.PL t/00_all.t t/01_bug_sundays_0th_or_earlier.t t/02_bug_nearest_dst.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) SIGNATURE Public-key signature (added by MakeMaker) Oxford-Calendar-2.10/t/0002755000175000017500000000000012466473164013006 5ustar domdomOxford-Calendar-2.10/t/00_all.t0000644000175000017500000000625412106536143014233 0ustar domdomuse strict; use warnings; use Test::More; use Test::Exception; use Date::Calc; use Oxford::Calendar; plan tests => 27; # Date in full term my $testdate1 = 'Sunday, 7th week, Hilary 2002'; is( Oxford::Calendar::ToOx(24, 2, 2002, { mode => 'nearest' } ), $testdate1 ); is( Oxford::Calendar::ToOx(24, 2, 2002, { mode => 'ext_term' } ), $testdate1 ); is( Oxford::Calendar::ToOx(24, 2, 2002, { mode => 'full_term' } ), $testdate1 ); is( Oxford::Calendar::FromOx( Oxford::Calendar::Parse($testdate1)), "24/2/2002" ); # Check the array mode my @ary = Oxford::Calendar::ToOx(24,2,2002); is( $ary[0], 'Sunday' ); # and with a date out of time (to test the nearest branch) my $testdate4 = 'Tuesday, -1st week, Hilary 2008'; @ary = Oxford::Calendar::ToOx(1,1,2008, { mode => 'nearest' }); is( $ary[0], 'Tuesday' ); # Date in extended term my $testdate2 = 'Friday, 9th week, Hilary 2009'; is( Oxford::Calendar::ToOx(20, 3, 2009, { mode => 'nearest' } ), $testdate2 ); is( Oxford::Calendar::ToOx(20, 3, 2009, { mode => 'ext_term' } ), $testdate2 ); is( Oxford::Calendar::ToOx(20, 3, 2009, { mode => 'full_term' } ), undef ); is( Oxford::Calendar::FromOx( Oxford::Calendar::Parse($testdate2)), "20/3/2009"); # Date not in term my $testdate3 = 'Thursday, 11th week, Michaelmas 2007'; is( Oxford::Calendar::ToOx(20, 12, 2007, { mode => 'nearest' } ), $testdate3 ); is( Oxford::Calendar::ToOx(20, 12, 2007, { mode => 'ext_term' } ), undef ); is( Oxford::Calendar::ToOx(20, 12, 2007, { mode => 'full_term' } ), undef ); is( Oxford::Calendar::FromOx( Oxford::Calendar::Parse($testdate3)), "20/12/2007"); # Some more dates is( Oxford::Calendar::ToOx(12, 1, 2008, { mode => 'ext_term' } ), 'Saturday, 0th week, Hilary 2008' ); is( Oxford::Calendar::ToOx(1, 1, 2008, { mode => 'ext_term' } ), undef ); # NextTerm my @next_term = Oxford::Calendar::NextTerm( 2008, 1, 1 ); is( $next_term[0], 2008 ); is( $next_term[1], 'Hilary' ); @next_term = Oxford::Calendar::NextTerm( 2008, 1, 14 ); is( $next_term[0], 2008 ); is( $next_term[1], 'Trinity' ); # Dies my @today = Date::Calc::Today; # Future proof the module by testing against a data in the future that we # never expect to have data for my $future_year = $today[0] + 50; throws_ok { Oxford::Calendar::ToOx( 1, 11, $future_year, { mode => 'full_term' } ) } qr/Date out of range/, 'ToOx out of range (in term)'; throws_ok { Oxford::Calendar::ToOx( 1, 11, $future_year, { mode => 'nearest' } ) } qr/Date out of range/, 'ToOx out of range (out of term)'; throws_ok { Oxford::Calendar::FromOx( $future_year, 'Hilary', 1, 'Sunday' ) } qr/No data for Hilary $future_year/, 'FromOx out of range'; # Provisional my $testdate5 = 'Thursday, -2nd week, Hilary 2018'; is( Oxford::Calendar::ToOx(28, 12, 2017, { mode => 'nearest', confirmed => 0 } ), $testdate5, 'Provisional date' ); is( Oxford::Calendar::ToOx(28, 12, 2017, { mode => 'nearest', confirmed => 1 } ), undef, 'Provisional date with confirmed => 1' ); my $testdate6 = 'Tuesday, 3rd week, Hilary 2018'; is( Oxford::Calendar::ToOx(30, 1, 2018, { mode => 'full_term', confirmed => 0 } ), $testdate6, 'Provisional date' ); is( Oxford::Calendar::ToOx(30, 1, 2018, { mode => 'full_term', confirmed => 1 } ), undef, 'Provisional date with confirmed => 1' ); Oxford-Calendar-2.10/t/02_bug_nearest_dst.t0000644000175000017500000000116611624243375016640 0ustar domdomuse strict; use warnings; use Test::More; use Test::Exception; use Oxford::Calendar; plan tests => 4; my @date = (25, 3, 2012); my $testdate = 'Sunday, 11th week, Hilary 2012'; is( Oxford::Calendar::ToOx(@date, { mode => 'nearest' } ), $testdate ); @date = (1, 4, 2012); $testdate = 'Sunday, -2nd week, Trinity 2012'; is( Oxford::Calendar::ToOx(@date, { mode => 'nearest' } ), $testdate ); @date = (28, 3, 2010); $testdate = 'Sunday, 11th week, Hilary 2010'; is( Oxford::Calendar::ToOx(@date, { mode => 'nearest' } ), $testdate ); @date = (4, 4, 2010); isnt( Oxford::Calendar::ToOx(@date, { mode => 'nearest' } ), $testdate ); Oxford-Calendar-2.10/t/01_bug_sundays_0th_or_earlier.t0000644000175000017500000000037511624243375020771 0ustar domdomuse strict; use warnings; use Test::More; use Test::Exception; use Oxford::Calendar; plan tests => 1; my @date = (18, 4, 2010); my $testdate = 'Sunday, 0th week, Trinity 2010'; is( Oxford::Calendar::ToOx(@date, { mode => 'nearest' } ), $testdate ); Oxford-Calendar-2.10/Makefile.PL0000644000175000017500000000110411624243375014501 0ustar domdomuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( (MM->can('signature_target') ? (SIGN => 1) : ()), 'NAME' => 'Oxford::Calendar', 'VERSION_FROM' => 'lib/Oxford/Calendar.pm', # finds $VERSION 'PREREQ_PM' => { Text::Abbrev => 0, Date::Calc => 0, YAML => 0, Time::Seconds => 0, Test::More => 0, Test::Exception => 0, Time::Piece => 0, }, # e.g., Module::Name => 1.1 ); Oxford-Calendar-2.10/lib/0002755000175000017500000000000012466473164013311 5ustar domdomOxford-Calendar-2.10/lib/Oxford/0002755000175000017500000000000012466473164014552 5ustar domdomOxford-Calendar-2.10/lib/Oxford/Calendar.pm0000644000175000017500000004522712466473121016622 0ustar domdom# Oxford University calendar conversion. # Simon Cozens (c) 1999-2002 # Eugene van der Pijll (c) 2004 # Dominic Hargreaves / University of Oxford (c) 2007-2015 # Artistic License package Oxford::Calendar; $Oxford::Calendar::VERSION = "2.10"; use strict; use Text::Abbrev; use Date::Calc qw(Add_Delta_Days Decode_Date_EU Delta_Days Mktime Easter_Sunday Date_to_Days Day_of_Week_to_Text Day_of_Week); use YAML; use Time::Seconds; use Time::Piece; use constant CALENDAR => '/etc/oxford-calendar.yaml'; use constant SEVEN_WEEKS => 7 * ONE_WEEK; use constant DEFAULT_MODE => 'nearest'; use constant TERMS => qw(Michaelmas Hilary Trinity); use constant DAYS => qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); # Constants defined by University regulations use constant MICHAELMAS_START => (10, 1); use constant MICHAELMAS_END => (12, 17); use constant HILARY_START => (1, 7); use constant HILARY_END_IF_EARLIER => (3, 25); use constant TRINITY_START_IF_LATER => (4, 20); use constant TRINITY_END => (7, 6); =head1 NAME Oxford::Calendar - University of Oxford calendar conversion routines =head1 SYNOPSIS use 5.10.0; use Oxford::Calendar; use Date::Calc; say "Today is " . Oxford::Calendar::ToOx(reverse Date::Calc::Today); =head1 DESCRIPTION This module converts University of Oxford dates (Oxford academic dates) to and from Real World dates, and provides information on Terms of the University. The Terms of the University are defined by the B, available online from L This document describes the start and end dates of Oxford Terms. In addition to this, the dates of Full Term, required to calculate the week number of the term, are prescribed by Council, and published periodically in the B. Full term comprises weeks 1-8 inclusive, but sometimes, dates outside of full term are presented in the Oxford academic date format. This module will optionally provide such dates. Data for these prescribed dates may be supplied in the file F; if this file does not exist, built-in data will be used. The built-in data is periodically updated from the semi-authoritative source at L. or the authoritative source, the Gazette, available online from L. L describes the academic year at Oxford. =head1 DATE FORMAT An Oxford academic date has the following format: =over , [st,nd,rd,th] week, =back where term name is one of =over =item * Michaelmas (autumn) =item * Hilary (spring) =item * Trinity (summer) =back Example: Friday, 8th Week, Michaelmas 2007 =cut our %db; my $_initcal; # If this is true, we have our database of dates already. my $_initrange; my @_oxford_full_terms; sub _get_week_suffix { my $week = shift; die "_get_week_suffix: No week given" unless defined $week; my $wsuffix = "th"; abs($week) == 1 && ( $wsuffix = "st" ); abs($week) == 2 && ( $wsuffix = "nd" ); abs($week) == 3 && ( $wsuffix = "rd" ); return $wsuffix; } sub _find_week { my $tm = shift; my $sweek = shift; my $sweek_tm = shift; my $eow = $sweek_tm + ONE_WEEK; while ( $tm >= $eow ) { $eow += ONE_WEEK; $sweek++; } return $sweek; } sub _init_db { my $db; if ( -r CALENDAR ) { $db = YAML::LoadFile(CALENDAR); } else { my $data = join '', ; $db = YAML::Load($data); } %db = %{ $db->{Calendar} }; } sub _init_range { foreach my $termspec ( keys %db ) { next unless $db{$termspec}; my $time = eval { Time::Piece->strptime($db{$termspec}->{start}, '%d/%m/%Y' ) } or die "Could not decode date ($db{$termspec}->{start}) for term $termspec: $@"; push @_oxford_full_terms, [$time, ($time + SEVEN_WEEKS), split(/ /, $termspec), $db{$termspec}->{provisional}]; } $_initrange++; } sub _fmt_oxdate_as_string { my ( $dow, $week, $term, $year ) = @_; my $wsuffix = _get_week_suffix($week); return "$dow, $week$wsuffix week, $term $year"; } sub _increment_term { my ( $year, $term ) = @_; if ( $term eq 'Michaelmas' ) { return $year + 1, 'Hilary'; } elsif ( $term eq 'Hilary' ) { return $year, 'Trinity' } elsif ( $term eq 'Trinity' ) { return $year, 'Michaelmas'; } else { die "_increment_term: Unknown term $term"; } } sub _sunday_of_first { my ( $year, $term ) = @_; Init() unless defined $_initcal; my $date = $db{"$term $year"}; return undef unless $date; return ( $date->{provisional}, Decode_Date_EU($date->{start}) ); } sub _to_ox_nearest { my @date = @_; my $confirmed = pop @date; my $week; my @term; _init_range() unless defined $_initrange; my $dow = Day_of_Week_to_Text( Day_of_Week( @date ) ); my $tm = Time::Piece->strptime(join('/', @date[0..2]), '%Y/%m/%d'); my @terms = sort { $a->[0] <=> $b->[0] } @_oxford_full_terms; my ( $prevterm, $nextterm ); my $curterm = shift @terms; while ($curterm) { if ( $tm < $curterm->[0] ) { if ( $prevterm && $tm >= ($prevterm->[1] + ONE_WEEK) ) { $nextterm = $curterm; last; } else { die "Date out of range"; } } $prevterm = $curterm; $curterm = shift @terms; } return undef unless $nextterm; # We are in the gap between terms .. which one is closest? my $prevgap = $tm - ($prevterm->[1] + ONE_WEEK); my $nextgap = $tm - $nextterm->[0]; if ( abs($prevgap) < abs($nextgap) ) { # if equal go for -th week $week = _find_week( $tm, 8, $prevterm->[1] ); @term = @{$prevterm}; } else { my $delta = $nextgap / (24 * 60 * 60); $week = 1 + int( $delta / 7 ); $week -= 1 if $delta % 7; @term = @{$nextterm}; } return undef if $term[4] && $confirmed; return ($dow, $week, $term[2], $term[3]) if ( wantarray ); return _fmt_oxdate_as_string( $dow, $week, $term[2], $term[3] ); } sub Init { _init_db; Date::Calc::Language(Date::Calc::Decode_Language('English')); $_initcal++; } =head1 FUNCTIONS =over 3 =item ToOx($day, $month, $year, [\%options]) Given a day, month and year in standard human format (that is, month is 1-12, not 0-11, and year is four digits) will return a string of the form Day, xth week, Term year or an array (Day, week of term, Term, year) depending on how it is called. The exact behaviour is modified by the 'mode' option described below. If the requested date is not in full term or extended term (see below), undef will be returned. If the requested date is not covered by the database, ToOx will die with an "out of range" error message. Therefore it is recommended to eval ToOx with appropriate error handling. %options can contain additional named parameter options: =over 5 =item mode Several modes are available: =over 6 =item full_term Term dates will only be returned if the date requested is part of a full term (as defined by the web page above). =item ext_term Term dates will only be returned if the date requested is part of an extended term, or statutory term. =item nearest Will return term dates based on the nearest term, even if the date requested is not part of an extended term (i.e. will include fictional week numbers). This is currently the default behaviour, for backwards compatibility with previous releases; this may be changed in future. =back =back =over 4 =item confirmed If true, ignores dates marked as provisional in the database. =back =cut sub ToOx { my (@dmy, $options); ($dmy[0], $dmy[1], $dmy[2], $options) = @_; my $mode = $options->{mode} || DEFAULT_MODE; my ($week, @term); my @date = reverse @dmy; Init unless defined $_initcal; my $dow = Day_of_Week_to_Text( Day_of_Week( @date ) ); @term = ThisTerm( @date ); if ( $#term ) { # We're in term my @term_start = _sunday_of_first( @term ); my $provisional = shift @term_start; die "Date out of range" unless ( $#term_start == 2 ); my $days_from_start = Delta_Days( @term_start, @date ); my $week_offset = $days_from_start < 0 ? 1 : 7; my $week = int( ( $days_from_start + $week_offset ) / 7); return undef if $options->{confirmed} && $provisional; return undef if ( ( $week < 1 || $week > 8 ) && $mode eq 'full_term' ); return ( $dow, $week, $term[1], $term[0] ) if ( wantarray ); return _fmt_oxdate_as_string( $dow, $week, $term[1], $term[0] ); } else { return undef if $mode eq 'full_term'; return undef if $mode eq 'ext_term'; return _to_ox_nearest( @date, $options->{confirmed} ); } } =item ThisTerm($year, $month, $day) Given a year, month, term in standard human format (that is, month is 1-12, not 0-11, and year is four digits) will returns the current term or undef if in vacation or unknown. The term is given as an array in the form (year, term). =cut sub ThisTerm { my ( $year, $month, $day ) = @_; my $term_dates = StatutoryTermDates( $year ); foreach my $term ( keys %{$term_dates} ) { my $start = Date_to_Days( @{$term_dates->{$term}->{start}} ); my $end = Date_to_Days( @{$term_dates->{$term}->{end}} ); my $date = Date_to_Days( $year, $month, $day ); if ( ( $date >= $start ) && ( $date <= $end )) { return ( $year, $term ); } } return undef; } =item NextTerm($year, $month, $day) Given a day, month and year in standard human format (that is, month is 1-12, not 0-11, and year is four digits) will return the next term (whether or not the date given is in term time). The term is given as an array in the form (year, term). =cut sub NextTerm { my @date = @_; my @next_term; my @this_term = ThisTerm( @date ); if ( @this_term == 2 ) { @next_term = _increment_term( @this_term ); } else { my @test_date = @date; while ( @next_term != 2 ) { @test_date = Add_Delta_Days( @test_date, 1 ); @next_term = ThisTerm( @test_date ); } } return @next_term; } =item StatutoryTermDates($year) Returns a hash reference keyed on terms for a given year, the value of each being a hash reference containing start and end dates for that term. The dates are stored as array references containing numeric year, month, day values. Note: these are the statutory term dates, not full term dates. =cut sub StatutoryTermDates { my $year = shift; die "StatutoryTermDates: no year given" unless $year; # Calculate end of Hilary my @palm_sunday = Date::Calc::Add_Delta_Days( Date::Calc::Easter_Sunday( $year ), -7 ); my @saturday_before_palm_sunday = Date::Calc::Add_Delta_Days( @palm_sunday, -6 ); my $hilary_delta = Date::Calc::Delta_Days( $year, HILARY_END_IF_EARLIER, @saturday_before_palm_sunday ); my @hilary_end; if ( $hilary_delta == 1 ) { @hilary_end = ( $year, HILARY_END_IF_EARLIER ); } else { @hilary_end = @saturday_before_palm_sunday; } # Calculate start of Trinity my @wednesday_after_easter_sunday = Date::Calc::Add_Delta_Days( Date::Calc::Easter_Sunday( $year ), 3 ); my $trinity_delta = Date::Calc::Delta_Days( @wednesday_after_easter_sunday, $year, TRINITY_START_IF_LATER ); my @trinity_start; if ( $trinity_delta == 1 ) { @trinity_start = ( $year, TRINITY_START_IF_LATER ); } else { @trinity_start = @wednesday_after_easter_sunday; } my $term_dates = { Michaelmas => { start => [$year, MICHAELMAS_START], end => [$year, MICHAELMAS_END] }, Hilary => { start => [$year, HILARY_START], end => [@hilary_end] }, Trinity => { start => [@trinity_start], end => [$year, TRINITY_END] } }; return $term_dates; } =item Parse($string) Takes a free-form description of an Oxford calendar date, and attempts to divine the expected meaning. If the name of a term is not found, the current term will be assumed. If the description is unparsable, undef is returned. Otherwise, an array will be returned of the form C<($year,$term,$week,$day)>. This function is experimental. =cut sub Parse { my $string = shift; my $term = ""; my ( $day, $week, $year ); $day = $week = $year = ""; $string = lc($string); $string =~ s/week//g; $string =~ s/(\d+)(?:rd|st|nd|th)/$1/; my %ab = Text::Abbrev::abbrev( DAYS, TERMS ); my $expand; while ( $string =~ s/((?:\d|-)\d*)/ / ) { if ( $1 > 50 ) { $year = $1; $year += 1900 if $year < 1900; } else { $week = $1 } } foreach ( sort { length $b <=> length $a } keys %ab ) { if ( $string =~ s/\b$_\w+//i ) { #pos($string)-=length($_); #my $foo=lc($_); $string=~s/\G$foo[a-z]*/ /i; $expand = $ab{$_}; $term = $expand if ( scalar( grep /$expand/, TERMS ) > 0 ); $day = $expand if ( scalar( grep /$expand/, DAYS ) > 0 ); } } unless ($day) { %ab = Text::Abbrev::abbrev(DAYS); foreach ( sort { length $b <=> length $a } keys %ab ) { if ( $string =~ /$_/ig ) { pos($string) -= length($_); my $foo = lc($_); $string =~ s/\G$foo[a-z]*/ /; $day = $ab{$_}; } } } unless ($term) { %ab = Text::Abbrev::abbrev(TERMS); foreach ( sort { length $b <=> length $a } keys %ab ) { if ( $string =~ /$_/ig ) { pos($string) -= length($_); my $foo = lc($_); $string =~ s/\G$foo[a-z]*/ /; $term = $ab{$_}; } } } # Assume this term? unless ($term) { $term = ToOx( reverse Date::Calc::Today() ); return "Can't work out what term" unless $term =~ /week/; $term =~ s/.*eek,\s+(\w+).*/$1/; } $year = ( Date::Calc::Today() )[0] unless $year; return undef unless defined $week and defined $day; return ( $year, $term, $week, $day ); } =item FromOx($year, $term, $week, $day) Converts an Oxford date into a Gregorian date, returning a string of the form C
or undef. The arguments are of the same format as returned by ToOx in array context; that is, a four-digit year, the name of the term, the week number, and the name of the day of week (e.g. 'Sunday'). If the requested date is not covered by the database, FromOx will die with an "out of range" error message. Therefore it is recommended to eval ToOx with appropriate error handling. =cut sub FromOx { my %lu; Init unless defined $_initcal; my ( $year, $term, $week, $day ); ( $year, $term, $week, $day ) = @_; $year =~ s/\s//g; $term =~ s/\s//g; die "No data for $term $year" unless exists $db{"$term $year"}; { my $foo = 0; %lu = ( map { $_, $foo++ } DAYS ); } my $delta = 7 * ( $week - 1 ) + $lu{$day}; my @start = _sunday_of_first( $year, $term ); shift @start; die "The internal database is bad for $term $year" unless $start[0]; return join "/", reverse( Date::Calc::Add_Delta_Days( @start, $delta ) ); } 1; =back =head1 BUGS Bugs may be browsed and submitted at L A copy of the maintainer's git repository may be found at L =head1 AUTHOR Simon Cozens is the original author of this module. Eugene van der Pijll, C took over maintenance from Simon for a time. Dominic Hargreaves currently maintains this module for IT Services, University of Oxford. =cut __DATA__ --- #YAML:1.0 Calendar: Hilary 2001: start: 14/01/2001 Hilary 2002: start: 13/01/2002 Hilary 2003: start: 19/01/2003 Hilary 2004: start: 18/01/2004 Hilary 2005: start: 16/01/2005 Hilary 2006: start: 15/01/2006 Hilary 2007: start: 14/01/2007 Hilary 2008: start: 13/01/2008 Hilary 2009: start: 18/01/2009 Hilary 2010: start: 17/01/2010 Hilary 2011: start: 16/01/2011 Hilary 2012: start: 15/01/2012 Hilary 2013: start: 13/01/2013 Hilary 2014: start: 19/01/2014 Hilary 2015: start: 18/01/2015 Hilary 2016: start: 17/01/2016 Hilary 2017: start: 15/01/2017 Hilary 2018: start: 14/01/2018 provisional: 1 Hilary 2019: start: 13/01/2019 provisional: 1 Hilary 2020: start: 19/01/2020 provisional: 1 Hilary 2021: start: 17/01/2021 provisional: 1 Michaelmas 2001: start: 07/10/2001 Michaelmas 2002: start: 13/10/2002 Michaelmas 2003: start: 12/10/2003 Michaelmas 2004: start: 10/10/2004 Michaelmas 2005: start: 09/10/2005 Michaelmas 2006: start: 08/10/2006 Michaelmas 2007: start: 07/10/2007 Michaelmas 2008: start: 12/10/2008 Michaelmas 2009: start: 11/10/2009 Michaelmas 2010: start: 10/10/2010 Michaelmas 2011: start: 09/10/2011 Michaelmas 2012: start: 07/10/2012 Michaelmas 2013: start: 13/10/2013 Michaelmas 2014: start: 12/10/2014 Michaelmas 2015: start: 11/10/2015 Michaelmas 2016: start: 09/10/2016 Michaelmas 2017: start: 08/10/2017 provisional: 1 Michaelmas 2018: start: 07/10/2018 provisional: 1 Michaelmas 2019: start: 13/10/2019 provisional: 1 Michaelmas 2020: start: 11/10/2020 provisional: 1 Trinity 2001: start: 22/04/2001 Trinity 2002: start: 21/04/2002 Trinity 2003: start: 27/04/2003 Trinity 2004: start: 25/04/2004 Trinity 2005: start: 24/04/2005 Trinity 2006: start: 23/04/2006 Trinity 2007: start: 22/04/2007 Trinity 2008: start: 20/04/2008 Trinity 2009: start: 26/04/2009 Trinity 2010: start: 25/04/2010 Trinity 2011: start: 01/05/2011 Trinity 2012: start: 22/04/2012 Trinity 2013: start: 21/04/2013 Trinity 2014: start: 27/04/2014 Trinity 2015: start: 26/04/2015 Trinity 2016: start: 24/04/2016 Trinity 2017: start: 23/04/2017 Trinity 2018: start: 22/04/2018 provisional: 1 Trinity 2019: start: 28/04/2019 provisional: 1 Trinity 2020: start: 26/04/2020 provisional: 1 Trinity 2021: start: 25/04/2021 provisional: 1