1Business::Hours(3)    User Contributed Perl Documentation   Business::Hours(3)
2
3
4

NAME

6       Business::Hours - Calculate business hours in a time period
7

SYNOPSIS

9         use Business::Hours;
10         my $hours = Business::Hours->new();
11
12         # Get a Set::IntSpan of all the business hours in the next week.
13         # use the default business hours of 9am to 6pm localtime.
14         $hours->for_timespan( Start => time(), End => time()+(86400*7) );
15

DESCRIPTION

17       This module is a simple tool for calculating business hours in a time
18       period.  Over time, additional functionality will be added to make it
19       easy to calculate the number of business hours between arbitrary dates.
20

USAGE

22   new
23       Creates a new Business::Hours object.  Takes no arguments.
24
25   business_hours HASH
26       Gets / sets the business hours for this object.  Takes a hash (NOT a
27       hash reference) of the form:
28
29           my %hours = (
30               0 => { Name     => 'Sunday',
31                      Start    => 'HH:MM',
32                      End      => 'HH:MM' },
33
34               1 => { Name     => 'Monday',
35                      Start    => 'HH:MM',
36                      End      => 'HH:MM' },
37               ....
38
39               6 => { Name     => 'Saturday',
40                      Start    => 'HH:MM',
41                      End      => 'HH:MM' },
42           );
43
44       Start and End times are of the form HH:MM.  Valid times are from 00:00
45       to 23:59.  If your hours are from 9am to 6pm, use Start => '9:00', End
46       => '18:00'.  A given day MUST have a start and end time OR may declare
47       both Start and End to be undef, if there are no valid hours on that
48       day.
49
50       You can use the array Breaks to mark interruptions between Start/End
51       (for instance lunch hour). It's an array of periods, each with a Start
52       and End time:
53
54           my %hours = (
55               0 => { Name     => 'Sunday',
56                      Start    => 'HH:MM',
57                      End      => 'HH:MM',
58                      Breaks  => [
59                                    { Start    => 'HH:MM',
60                                    End      => 'HH:MM' },
61                                    { Start    => 'HH:MM',
62                                    End      => 'HH:MM' },
63                                  ],
64
65               1 => { Name     => 'Monday',
66                      Start    => 'HH:MM',
67                      End      => 'HH:MM' },
68               ....
69
70               6 => { Name     => 'Saturday',
71                      Start    => 'HH:MM',
72                      End      => 'HH:MM' },
73           );
74
75       Note that the ending time is really "what is the first minute we're
76       closed.  If you specifiy an "End" of 18:00, that means that at 6pm, you
77       are closed.  The last business second was 17:59:59.
78
79       As well, you can pass information about holidays using key 'holidays'
80       and an array reference value, for example:
81
82           $hours->business_hours(
83               0 => { Name     => 'Sunday',
84                      Start    => 'HH:MM',
85                      End      => 'HH:MM' },
86               ....
87               6 => { Name     => 'Saturday',
88                      Start    => 'HH:MM',
89                      End      => 'HH:MM' },
90
91               holidays => [qw(01-01 12-25 2009-05-08)],
92           );
93
94       Read more about holidays specification below in holidays.
95
96   preprocess_business_hours
97       Checks and transforms business hours data. No need to call it.
98
99   holidays ARRAY
100       Gets / sets holidays for this object. Takes an array where each element
101       is ether 'MM-DD' or 'YYYY-MM-DD'.
102
103       Specification with year defined may be required when a holiday matches
104       Sunday or Saturday. In many countries days are shifted in such case.
105
106       Holidays can be set via business_hours method as well, so you can use
107       this feature without changing your code.
108
109   for_timespan HASH
110       Takes a hash with the following parameters:
111
112       Start
113           The start of the period in question in seconds since the epoch
114
115       End The end of the period in question in seconds since the epoch
116
117       Returns a Set::IntSpan of business hours for this period of time.
118
119   between START, END
120       Returns the number of business seconds between START and END Both START
121       and END should be specified in seconds since the epoch.
122
123       Returns -1 if START or END are outside the calculated business hours.
124
125   first_after START
126       Returns START if START is within business hours.  Otherwise, returns
127       the next business second after START.  START should be specified in
128       seconds since the epoch.
129
130       Returns -1 if it can't find any business hours within thirty days.
131
132   add_seconds START, SECONDS
133       Returns a time SECONDS business seconds after START.  START should be
134       specified in seconds since the epoch.
135
136       Returns -1 if it can't find any business hours within thirty days.
137

BUGS

139       Yes, most likely.  Please report them to
140       bug-business-hours@rt.cpan.org.
141

AUTHOR

143       Jesse Vincent, jesse@cpan.org
144
146       Copyright 2003-2008 Best Practical Solutions, LLC.
147
148       This program is free software; you can redistribute it and/or modify it
149       under the same terms as Perl itself.
150
151       The full text of the license can be found in the LICENSE file included
152       with this module.
153
154
155
156perl v5.36.0                      2022-07-22                Business::Hours(3)
Impressum