.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Business::Hours 3pm" .TH Business::Hours 3pm "2019-01-16" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Business::Hours \- Calculate business hours in a time period .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Business::Hours; \& my $hours = Business::Hours\->new(); \& \& # Get a Set::IntSpan of all the business hours in the next week. \& # use the default business hours of 9am to 6pm localtime. \& $hours\->for_timespan( Start => time(), End => time()+(86400*7) ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module is a simple tool for calculating business hours in a time period. Over time, additional functionality will be added to make it easy to calculate the number of business hours between arbitrary dates. .SH "USAGE" .IX Header "USAGE" .SS "new" .IX Subsection "new" Creates a new Business::Hours object. Takes no arguments. .SS "business_hours \s-1HASH\s0" .IX Subsection "business_hours HASH" Gets / sets the business hours for this object. Takes a hash (\s-1NOT\s0 a hash reference) of the form: .PP .Vb 4 \& my %hours = ( \& 0 => { Name => \*(AqSunday\*(Aq, \& Start => \*(AqHH:MM\*(Aq, \& End => \*(AqHH:MM\*(Aq }, \& \& 1 => { Name => \*(AqMonday\*(Aq, \& Start => \*(AqHH:MM\*(Aq, \& End => \*(AqHH:MM\*(Aq }, \& .... \& \& 6 => { Name => \*(AqSaturday\*(Aq, \& Start => \*(AqHH:MM\*(Aq, \& End => \*(AqHH:MM\*(Aq }, \& ); .Ve .PP Start and End times are of the form \s-1HH:MM.\s0 Valid times are from 00:00 to 23:59. If your hours are from 9am to 6pm, use Start => '9:00', End => '18:00'. A given day \s-1MUST\s0 have a start and end time \s-1OR\s0 may declare both Start and End to be undef, if there are no valid hours on that day. .PP You can use the array Breaks to mark interruptions between Start/End (for instance lunch hour). It's an array of periods, each with a Start and End time: .PP .Vb 10 \& my %hours = ( \& 0 => { Name => \*(AqSunday\*(Aq, \& Start => \*(AqHH:MM\*(Aq, \& End => \*(AqHH:MM\*(Aq, \& Breaks => [ \& { Start => \*(AqHH:MM\*(Aq, \& End => \*(AqHH:MM\*(Aq }, \& { Start => \*(AqHH:MM\*(Aq, \& End => \*(AqHH:MM\*(Aq }, \& ], \& \& 1 => { Name => \*(AqMonday\*(Aq, \& Start => \*(AqHH:MM\*(Aq, \& End => \*(AqHH:MM\*(Aq }, \& .... \& \& 6 => { Name => \*(AqSaturday\*(Aq, \& Start => \*(AqHH:MM\*(Aq, \& End => \*(AqHH:MM\*(Aq }, \& ); .Ve .PP Note that the ending time is really \*(L"what is the first minute we're closed. If you specify an \*(R"End" of 18:00, that means that at 6pm, you are closed. The last business second was 17:59:59. .PP As well, you can pass information about holidays using key 'holidays' and an array reference value, for example: .PP .Vb 8 \& $hours\->business_hours( \& 0 => { Name => \*(AqSunday\*(Aq, \& Start => \*(AqHH:MM\*(Aq, \& End => \*(AqHH:MM\*(Aq }, \& .... \& 6 => { Name => \*(AqSaturday\*(Aq, \& Start => \*(AqHH:MM\*(Aq, \& End => \*(AqHH:MM\*(Aq }, \& \& holidays => [qw(01\-01 12\-25 2009\-05\-08)], \& ); .Ve .PP Read more about holidays specification below in holidays. .SS "preprocess_business_hours" .IX Subsection "preprocess_business_hours" Checks and transforms business hours data. No need to call it. .SS "holidays \s-1ARRAY\s0" .IX Subsection "holidays ARRAY" Gets / sets holidays for this object. Takes an array where each element is ether '\s-1MM\-DD\s0' or '\s-1YYYY\-MM\-DD\s0'. .PP Specification with year defined may be required when a holiday matches Sunday or Saturday. In many countries days are shifted in such case. .PP Holidays can be set via business_hours method as well, so you can use this feature without changing your code. .SS "for_timespan \s-1HASH\s0" .IX Subsection "for_timespan HASH" Takes a hash with the following parameters: .IP "Start" 4 .IX Item "Start" The start of the period in question in seconds since the epoch .IP "End" 4 .IX Item "End" The end of the period in question in seconds since the epoch .PP Returns a Set::IntSpan of business hours for this period of time. .SS "between \s-1START, END\s0" .IX Subsection "between START, END" Returns the number of business seconds between \s-1START\s0 and \s-1END\s0 Both \s-1START\s0 and \s-1END\s0 should be specified in seconds since the epoch. .PP Returns \-1 if \s-1START\s0 or \s-1END\s0 are outside the calculated business hours. .SS "first_after \s-1START\s0" .IX Subsection "first_after START" Returns \s-1START\s0 if \s-1START\s0 is within business hours. Otherwise, returns the next business second after \s-1START. START\s0 should be specified in seconds since the epoch. .PP Returns \-1 if it can't find any business hours within thirty days. .SS "add_seconds \s-1START, SECONDS\s0" .IX Subsection "add_seconds START, SECONDS" Returns a time \s-1SECONDS\s0 business seconds after \s-1START. START\s0 should be specified in seconds since the epoch. .PP Returns \-1 if it can't find any business hours within thirty days. .SH "BUGS" .IX Header "BUGS" Yes, most likely. Please report them to bug\-business\-hours@rt.cpan.org. .SH "AUTHOR" .IX Header "AUTHOR" Jesse Vincent, jesse@cpan.org .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2003\-2008 Best Practical Solutions, \s-1LLC.\s0 .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP The full text of the license can be found in the \s-1LICENSE\s0 file included with this module.