src/dt_accessor.c

filter: Statementstmt 85.7% 24 / 28 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 85.7% 24 / 28 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« src/moment_parse.c ↑ Summary src/moment_fmt.c »
1 /*
2 * Copyright (c) 2012-2014 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 <stddef.h>
27 #include "dt_core.h"
28  
29 dt_t
30 0 dt_from_cjdn(int n) {
31 0 return dt_from_rdn(n - 1721425);
32 }
33  
34 int
35 0 dt_cjdn(dt_t dt) {
36 0 return dt_rdn(dt) + 1721425;
37 }
38  
39 int
40 3777 dt_year(dt_t dt) {
41 int y;
42 3777 dt_to_yd(dt, &y, NULL);
43 3777 return y;
44 }
45  
46 int
47 7 dt_quarter(dt_t dt) {
48 int q;
49 7 dt_to_yqd(dt, NULL, &q, NULL);
50 7 return q;
51 }
52  
53 int
54 29827 dt_month(dt_t dt) {
55 int m;
56 29827 dt_to_ymd(dt, NULL, &m, NULL);
57 29827 return m;
58 }
59  
60 int
61 413 dt_doy(dt_t dt) {
62 int d;
63 413 dt_to_yd(dt, NULL, &d);
64 413 return d;
65 }
66  
67 int
68 95 dt_doq(dt_t dt) {
69 int d;
70 95 dt_to_yqd(dt, NULL, NULL, &d);
71 95 return d;
72 }
73  
74 int
75 851 dt_dom(dt_t dt) {
76 int d;
77 851 dt_to_ymd(dt, NULL, NULL, &d);
78 851 return d;
79 }
80  
81 int
82 20 dt_woy(dt_t dt) {
83 int w;
84 20 dt_to_ywd(dt, NULL, &w, NULL);
85 20 return w;
86 }
87  
88 int
89 28 dt_yow(dt_t dt) {
90 int y;
91 28 dt_to_ywd(dt, &y, NULL, NULL);
92 28 return y;
93 }
94  
« src/moment_parse.c ↑ Summary src/moment_fmt.c »