src/dt_easter.c

filter: Statementstmt 61.5% 8 / 13 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 58.8% 10 / 17 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/dt_util.c ↑ Summary src/dt_parse_iso.c »
1 /*
2 * Copyright (c) 2012-2015 Christian Hansen <chansen@cpan.org>
3 * <https://github.com/chansen/c-dt>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 #include "dt_core.h"
27 #include "dt_easter.h"
28  
29 /*
30 * Easter algorithms by Al Petrofsky, San Mateo County, California, U.S.A.
31 * <http://petrofsky.org/>
32 */
33 static int
34 500 easter_gregorian(unsigned int y) {
35 unsigned int a, b;
36 500 a = y/100 * 1483 - y/400 * 2225 + 2613;
37 500 b = ((y % 19 * 3510 + a/25 * 319) / 330) % 29;
38 500 return 56 - b - ((y * 5/4) + a - b) % 7;
39 }
40  
41 static int
42 0 easter_julian(unsigned int y) {
43 unsigned int a;
44 0 a = (y % 19 * 19 + 15) % 30;
45 0 return 28 + a - ((y * 5/4) + a) % 7;
46 }
47  
48 dt_t
49 500 dt_from_easter(int y, dt_computus_t computus) {
50 500 ▶ if (y < 1)
Branch: 1 branch
BranchTrueFalseTotal
if (y < 1) 0 500 500
51 0 return 0;
52 500 ▶ if (computus == DT_WESTERN)
Branch: 1 branch
BranchTrueFalseTotal
if (computus == DT_WESTERN) 500 0 500
53 500 return dt_from_ymd(y, 3, easter_gregorian(y));
54 else
55 0 return dt_from_ymd(y, 3, easter_julian(y) + y/100 - y/400 - 2);
56 }
57  
« src/dt_util.c ↑ Summary src/dt_parse_iso.c »