File Coverage

blib/lib/Calendar/Bahai.pm
Criterion Covered Total %
statement 17 49 34.6
branch 0 10 0.0
condition 0 6 0.0
subroutine 6 14 42.8
pod 5 8 62.5
total 28 87 32.1


line stmt bran cond sub pod time code
1             package Calendar::Bahai;
2              
3             $Calendar::Bahai::VERSION = '0.44';
4             $Calendar::Bahai::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Calendar::Bahai - Interface to the calendar used by Bahai faith.
9              
10             =head1 VERSION
11              
12             Version 0.44
13              
14             =cut
15              
16 4     4   95013 use 5.006;
  4         10  
17 4     4   2239 use Data::Dumper;
  4         28478  
  4         189  
18              
19 4     4   2021 use Date::Bahai::Simple;
  4         1456169  
  4         111  
20 4     4   24 use Moo;
  4         5  
  4         12  
21 4     4   670 use namespace::clean;
  4         4  
  4         14  
22             with 'Calendar::Plugin::Renderer';
23              
24 4     4   535 use overload q{""} => 'as_string', fallback => 1;
  4         4  
  4         19  
25              
26             has year => (is => 'rw', predicate => 1);
27             has month => (is => 'rw', predicate => 1);
28             has date => (is => 'ro', default => sub { Date::Bahai::Simple->new });
29              
30             sub BUILD {
31 0     0 0   my ($self) = @_;
32              
33 0 0         $self->date->validate_month($self->month) if $self->has_month;
34 0 0         $self->date->validate_year($self->year) if $self->has_year;
35              
36 0 0 0       unless ($self->has_year && $self->has_month) {
37 0           $self->year($self->date->get_year);
38 0           $self->month($self->date->month);
39             }
40             }
41              
42             =head1 DESCRIPTION
43              
44             The Bahai calendar started from the original Badi calendar, created by the Bab.
45             The Bahai calendar is composed of 19 months, each with 19 days. Years in the
46             Bahai calendar are counted from Thursday, 21 March 1844, the beginning of the
47             Bahai Era or Badi Era (abbreviated BE or B.E.). Year 1 BE thus began at sundown
48             20 March 1844. Using the Bahai names for the weekday and month, day one of the
49             Bahai Era was Istijlal (Majesty), 1 Baha (Splendour) 1 BE.
50              
51             +----------------------------------------------------------------------------+
52             | Baha [172 BE] |
53             +----------+----------+----------+----------+----------+----------+----------+
54             | Jamal | Kamal | Fidal | Idal | Istijlal | Istiqlal | Jalal |
55             +----------+----------+----------+----------+----------+----------+----------+
56             | | 1 |
57             +----------+----------+----------+----------+----------+----------+----------+
58             | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
59             +----------+----------+----------+----------+----------+----------+----------+
60             | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
61             +----------+----------+----------+----------+----------+----------+----------+
62             | 16 | 17 | 18 | 19 | |
63             +----------+----------+----------+----------+----------+----------+----------+
64              
65             The package L<App::calendr> provides command line tool C<calendr> to display the
66             supported calendars on the terminal.
67              
68             =head1 SYNOPSIS
69              
70             use strict; use warnings;
71             use Calendar::Bahai;
72              
73             # prints current month bahai calendar
74             print Calendar::Bahai->new, "\n";
75             print Calendar::Bahai->new->current, "\n";
76              
77             # prints bahai month calendar for the first month of year 172.
78             print Calendar::Bahai->new({ month => 1, year => 172 }), "\n";
79              
80             # prints bahai month calendar in which the given gregorian date falls in.
81             print Calendar::Bahai->new->from_gregorian(2015, 1, 14), "\n";
82              
83             # prints bahai month calendar in which the given julian date falls in.
84             print Calendar::Bahai->new->from_julian(2457102.5), "\n";
85              
86             # prints current month bahai calendar in SVG format.
87             print Calendar::Bahai->new->as_svg;
88              
89             # prints current month bahai calendar in text format.
90             print Calendar::Bahai->new->as_text;
91              
92             =head1 BAHAI MONTHS
93              
94             +-------+-------------+----------------+------------------------------------+
95             | Month | Arabic Name | English Name | Gregorian Dates |
96             +-------+-------------+----------------+------------------------------------+
97             | 1 | Baha | Splendour | 21 Mar - 08 Apr |
98             | 2 | Jalal | Glory | 09 Apr - 27 Apr |
99             | 3 | Jamal | Beauty | 28 Apr - 16 May |
100             | 4 | Azamat | Grandeur | 17 May - 04 Jun |
101             | 5 | Nur | Light | 05 Jun - 23 Jun |
102             | 6 | Rahmat | Mercy | 24 Jun - 12 Jul |
103             | 7 | Kalimat | Words | 13 Jul - 31 Jul |
104             | 8 | Kamal | Perfection | 01 Aug - 19 Aug |
105             | 9 | Asma | Names | 20 Aug - 07 Sep |
106             | 10 | Izzat | Might | 08 Sep - 26 Sep |
107             | 11 | Mashiyyat | Will | 27 Sep - 15 Oct |
108             | 12 | Ilm | Knowledge | 16 Oct - 03 Nov |
109             | 13 | Qudrat | Power | 04 Nov - 22 Nov |
110             | 14 | Qawl | Speech | 23 Nov - 11 Dec |
111             | 15 | Masail | Questions | 12 Dec - 30 Dec |
112             | 16 | Sharaf | Honour | 31 Dec - 18 Jan |
113             | 17 | Sultan | Sovereignty | 19 Jan - 06 Feb |
114             | 18 | Mulk | Dominion | 07 Feb - 25 Feb |
115             | | Ayyam-i-Ha | The Days of Ha | 26 Feb - 01 Mar |
116             | 19 | Ala | Loftiness | 02 Mar - 20 Mar (Fasting Month) |
117             +-------+-------------+----------------+------------------------------------+
118              
119             =head1 BAHAI DAYS
120              
121             +-------------+--------------+----------------------------------------------+
122             | Arabic Name | English Name | Day of the Week |
123             +-------------+--------------+----------------------------------------------+
124             | Jamal | Beauty | Sunday |
125             | Kamal | Perfection | Monday |
126             | Fidal | Grace | Tuesday |
127             | Idal | Justice | Wednesday |
128             | Istijlal | Majesty | Thursday |
129             | Istiqlal | Independence | Friday |
130             | Jalal | Glory | Saturday |
131             +-------------+--------------+----------------------------------------------+
132              
133             =head1 KULL-i-SHAY / VAHID
134              
135             Also existing in the Bahai calendar system is a 19-year cycle called Vahid and a
136             361-year (19x19) supercycle called Kull-i-Shay (literally, "All Things"). Each of
137             the 19 years in a Vahid has been given a name as shown in the table below.The 9th
138             Vahid of the 1st Kull-i-Shay started on 21 March 1996, and the 10th Vahid will
139             begin in 2015. The current Bahai year,year 168 BE (21 March 2011 - 20 March 2012)
140             , is year Badi of the 9th Vahid of the 1st Kull-i-Shay. The 2nd Kull-i-Shay will
141             begin in 2205.
142              
143             =head2 1st Kull-i-Shay
144              
145             +----+--------+---------------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
146             | No.| Name | Meaning | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
147             +----+--------+---------------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
148             | 1 | Alif | A | 1844 | 1863 | 1882 | 1901 | 1920 | 1939 | 1958 | 1977 | 1996 | 2015 | 2034 | 2053 | 2072 | 2091 | 2110 | 2129 | 2148 | 2167 | 2186 |
149             | 2 | Ba | B | 1845 | 1864 | 1883 | 1902 | 1921 | 1940 | 1959 | 1978 | 1997 | 2016 | 2035 | 2054 | 2073 | 2092 | 2111 | 2130 | 2149 | 2168 | 2187 |
150             | 3 | Ab | Father | 1846 | 1865 | 1884 | 1903 | 1922 | 1941 | 1960 | 1979 | 1998 | 2017 | 2036 | 2055 | 2074 | 2093 | 2112 | 2131 | 2150 | 2169 | 2188 |
151             | 4 | Dal | D | 1847 | 1866 | 1885 | 1904 | 1923 | 1942 | 1961 | 1980 | 1999 | 2018 | 2037 | 2056 | 2075 | 2094 | 2113 | 2132 | 2151 | 2170 | 2189 |
152             | 5 | Bab | Gate | 1848 | 1867 | 1886 | 1905 | 1924 | 1943 | 1962 | 1981 | 2000 | 2019 | 2038 | 2057 | 2076 | 2095 | 2114 | 2133 | 2152 | 2171 | 2190 |
153             | 6 | Vav | V | 1849 | 1868 | 1887 | 1906 | 1925 | 1944 | 1963 | 1982 | 2001 | 2020 | 2039 | 2058 | 2077 | 2096 | 2115 | 2134 | 2153 | 2172 | 2191 |
154             | 7 | Abad | Eternity | 1850 | 1869 | 1888 | 1907 | 1926 | 1945 | 1964 | 1983 | 2002 | 2021 | 2040 | 2059 | 2078 | 2097 | 2116 | 2135 | 2154 | 2173 | 2192 |
155             | 8 | Jad | Generosity | 1851 | 1870 | 1889 | 1908 | 1927 | 1946 | 1965 | 1984 | 2003 | 2022 | 2041 | 2060 | 2079 | 2098 | 2117 | 2136 | 2155 | 2174 | 2193 |
156             | 9 | Baha | Splendour | 1852 | 1871 | 1890 | 1909 | 1928 | 1947 | 1966 | 1985 | 2004 | 2023 | 2042 | 2061 | 2080 | 2099 | 2118 | 2137 | 2156 | 2175 | 2194 |
157             | 10 | Hubb | Love | 1853 | 1872 | 1891 | 1910 | 1929 | 1948 | 1967 | 1986 | 2005 | 2024 | 2043 | 2062 | 2081 | 2100 | 2119 | 2138 | 2157 | 2176 | 2195 |
158             | 11 | Bahhaj | Delightful | 1854 | 1873 | 1892 | 1911 | 1930 | 1949 | 1968 | 1987 | 2006 | 2025 | 2044 | 2063 | 2082 | 2101 | 2120 | 2139 | 2158 | 2177 | 2196 |
159             | 12 | Javab | Answer | 1855 | 1874 | 1893 | 1912 | 1931 | 1950 | 1969 | 1988 | 2007 | 2026 | 2045 | 2064 | 2083 | 2102 | 2121 | 2140 | 2159 | 2178 | 2197 |
160             | 13 | Ahad | Single | 1856 | 1875 | 1894 | 1913 | 1932 | 1951 | 1970 | 1989 | 2008 | 2027 | 2046 | 2065 | 2084 | 2103 | 2122 | 2141 | 2160 | 2179 | 2198 |
161             | 14 | Vahhab | Bountiful | 1857 | 1876 | 1895 | 1914 | 1933 | 1952 | 1971 | 1990 | 2009 | 2028 | 2047 | 2066 | 2085 | 2104 | 2123 | 2142 | 2161 | 2180 | 2199 |
162             | 15 | Vidad | Affection | 1858 | 1877 | 1896 | 1915 | 1934 | 1953 | 1972 | 1991 | 2010 | 2029 | 2048 | 2067 | 2086 | 2105 | 2124 | 2143 | 2162 | 2181 | 2200 |
163             | 16 | Badi | Beginning | 1859 | 1878 | 1897 | 1916 | 1935 | 1954 | 1973 | 1992 | 2011 | 2030 | 2049 | 2068 | 2087 | 2106 | 2125 | 2144 | 2163 | 2182 | 2201 |
164             | 17 | Bahi | Luminous | 1860 | 1879 | 1898 | 1917 | 1936 | 1955 | 1974 | 1993 | 2012 | 2031 | 2050 | 2069 | 2088 | 2107 | 2126 | 2145 | 2164 | 2183 | 2202 |
165             | 18 | Abha | Most Luminous | 1861 | 1880 | 1899 | 1918 | 1937 | 1956 | 1975 | 1994 | 2013 | 2032 | 2051 | 2070 | 2089 | 2108 | 2127 | 2146 | 2165 | 2184 | 2203 |
166             | 19 | Vahid | Unity | 1862 | 1881 | 1900 | 1919 | 1938 | 1957 | 1976 | 1995 | 2014 | 2033 | 2052 | 2071 | 2090 | 2109 | 2128 | 2147 | 2166 | 2185 | 2204 |
167             +----+--------+---------------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+------+
168              
169             =head1 NOTE
170              
171             On July 10, 2014, the Universal House of Justice announced three decisions
172             regarding the Badi` (Bahai) calendar, which will affect the dates of Feasts and
173             Holy Days. Naw Ruz will usually fall on March 20th,which means that all the Feast
174             days will be one day earlier,and the births of the Bab and of Baha'u'llah will be
175             celebrated on two consecutive days in the Autumn.The changes take effect from the
176             next Bahai New Year, from sunset on March 20, 2015. The definitive tables showing
177             the new dates have not yet been released (as of September 24, 2014), but there is
178             a preliminary discussion L<here|http://senmcglinn.wordpress.com/2014/09/22/changes-in-bahai-calendar-what-how-why>.
179              
180             =head1 CONSTRUCTOR
181              
182             It expects month and year optionally. By default it gets current Bahai month and
183             year.
184              
185             =head1 METHODS
186              
187             =head2 current()
188              
189             Returns current month of the Bahai calendar.
190              
191             =cut
192              
193             sub current {
194 0     0 1   my ($self) = @_;
195              
196 0           return $self->as_text($self->date->month, $self->date->year);
197             }
198              
199             =head2 from_gregorian($year, $month, $day)
200              
201             Returns bahai month calendar in which the given gregorian date falls in.
202              
203             =cut
204              
205             sub from_gregorian {
206 0     0 1   my ($self, $year, $month, $day) = @_;
207              
208 0           return $self->from_julian($self->date->gregorian_to_julian($year, $month, $day));
209             }
210              
211             =head2 from_julian($julian_date)
212              
213             Returns bahai month calendar in which the given julian date falls in.
214              
215             =cut
216              
217             sub from_julian {
218 0     0 1   my ($self, $julian_date) = @_;
219              
220 0           my $date = $self->date->from_julian($julian_date);
221 0           return $self->as_text($date->month, $date->year);
222             }
223              
224             =head2 as_svg($month, $year)
225              
226             Returns calendar for the given C<$month> and C<$year> rendered in SVG format.
227             C<$month> can be a number between 1 and 19 or a valid Bahai month name. If
228             C<$month> and C<$year> missing, it would return current calendar month.
229              
230             =cut
231              
232             sub as_svg {
233 0     0 1   my ($self, $month, $year) = @_;
234              
235 0           ($month, $year) = $self->validate_params($month, $year);
236 0           my $date = $self->date->get_date(1, $month, $year);
237              
238 0           return $self->svg_calendar(
239             {
240             adjust_height => 21,
241             start_index => $date->day_of_week,
242             month_name => $date->get_month_name,
243             days => 19,
244             year => $year
245             });
246             }
247              
248             =head2 as_text($month, $year)
249              
250             Returns color coded Bahai calendar for the given C<$month> and C<$year>. C<$month>
251             can be a number between 1 and 19 or a valid Bahai month name. If C<$month> and
252             C<$year> missing, it would return current calendar month.
253              
254             =cut
255              
256             sub as_text {
257 0     0 1   my ($self, $month, $year) = @_;
258              
259 0           ($month, $year) = $self->validate_params($month, $year);
260 0           my $date = $self->date->get_date(1, $month, $year);
261              
262 0           return $self->text_calendar(
263             {
264             start_index => $date->day_of_week,
265             month_name => $date->get_month_name($month),
266             days => 19,
267             day_names => $date->days,
268             year => $year
269             });
270             }
271              
272             sub as_string {
273 0     0 0   my ($self) = @_;
274              
275 0           return $self->as_text($self->month, $self->year);
276             }
277              
278             #
279             #
280             # PRIVATE METHODS
281              
282             sub validate_params {
283 0     0 0   my ($self, $month, $year) = @_;
284              
285 0 0 0       if (defined $month && defined $year) {
286 0           $self->date->validate_month($month);
287 0           $self->date->validate_year($year);
288              
289 0 0         if ($month !~ /^\d+$/) {
290 0           $month = $self->date->get_month_number($month);
291             }
292             }
293             else {
294 0           $month = $self->month;
295 0           $year = $self->year;
296             }
297              
298 0           return ($month, $year);
299             }
300              
301             =head1 AUTHOR
302              
303             Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
304              
305             =head1 REPOSITORY
306              
307             L<https://github.com/manwar/Calendar-Bahai>
308              
309             =head1 SEE ALSO
310              
311             =over 4
312              
313             =item L<Calendar::Gregorian>
314              
315             =item L<Calendar::Hijri>
316              
317             =item L<Calendar::Persian>
318              
319             =item L<Calendar::Saka>
320              
321             =back
322              
323             =head1 BUGS
324              
325             Please report any bugs / feature requests to C<bug-calendar-bahai at rt.cpan.org>,
326             or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Calendar-Bahai>.
327             I will be notified, and then you'll automatically be notified of progress on your
328             bug as I make changes.
329              
330             =head1 SUPPORT
331              
332             You can find documentation for this module with the perldoc command.
333              
334             perldoc Calendar::Bahai
335              
336             You can also look for information at:
337              
338             =over 4
339              
340             =item * RT: CPAN's request tracker
341              
342             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Calendar-Bahai>
343              
344             =item * AnnoCPAN: Annotated CPAN documentation
345              
346             L<http://annocpan.org/dist/Calendar-Bahai>
347              
348             =item * CPAN Ratings
349              
350             L<http://cpanratings.perl.org/d/Calendar-Bahai>
351              
352             =item * Search CPAN
353              
354             L<http://search.cpan.org/dist/Calendar-Bahai/>
355              
356             =back
357              
358             =head1 LICENSE AND COPYRIGHT
359              
360             Copyright (C) 2011 - 2016 Mohammad S Anwar.
361              
362             This program is free software; you can redistribute it and / or modify it under
363             the terms of the the Artistic License (2.0). You may obtain a copy of the full
364             license at:
365              
366             L<http://www.perlfoundation.org/artistic_license_2_0>
367              
368             Any use, modification, and distribution of the Standard or Modified Versions is
369             governed by this Artistic License.By using, modifying or distributing the Package,
370             you accept this license. Do not use, modify, or distribute the Package, if you do
371             not accept this license.
372              
373             If your Modified Version has been derived from a Modified Version made by someone
374             other than you,you are nevertheless required to ensure that your Modified Version
375             complies with the requirements of this license.
376              
377             This license does not grant you the right to use any trademark, service mark,
378             tradename, or logo of the Copyright Holder.
379              
380             This license includes the non-exclusive, worldwide, free-of-charge patent license
381             to make, have made, use, offer to sell, sell, import and otherwise transfer the
382             Package with respect to any patent claims licensable by the Copyright Holder that
383             are necessarily infringed by the Package. If you institute patent litigation
384             (including a cross-claim or counterclaim) against any party alleging that the
385             Package constitutes direct or contributory patent infringement,then this Artistic
386             License to you shall terminate on the date that such litigation is filed.
387              
388             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
389             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
390             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
391             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
392             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
393             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
394             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
395              
396             =cut
397              
398             1; # End of Calendar::Bahai