1*d19ef5a2SAaron LI /*- 2*d19ef5a2SAaron LI * SPDX-License-Identifier: BSD-3-Clause 3*d19ef5a2SAaron LI * 4*d19ef5a2SAaron LI * Copyright (c) 2019-2020 The DragonFly Project. All rights reserved. 5*d19ef5a2SAaron LI * 6*d19ef5a2SAaron LI * This code is derived from software contributed to The DragonFly Project 7*d19ef5a2SAaron LI * by Aaron LI <aly@aaronly.me> 8*d19ef5a2SAaron LI * 9*d19ef5a2SAaron LI * Redistribution and use in source and binary forms, with or without 10*d19ef5a2SAaron LI * modification, are permitted provided that the following conditions 11*d19ef5a2SAaron LI * are met: 12*d19ef5a2SAaron LI * 13*d19ef5a2SAaron LI * 1. Redistributions of source code must retain the above copyright 14*d19ef5a2SAaron LI * notice, this list of conditions and the following disclaimer. 15*d19ef5a2SAaron LI * 2. Redistributions in binary form must reproduce the above copyright 16*d19ef5a2SAaron LI * notice, this list of conditions and the following disclaimer in 17*d19ef5a2SAaron LI * the documentation and/or other materials provided with the 18*d19ef5a2SAaron LI * distribution. 19*d19ef5a2SAaron LI * 3. Neither the name of The DragonFly Project nor the names of its 20*d19ef5a2SAaron LI * contributors may be used to endorse or promote products derived 21*d19ef5a2SAaron LI * from this software without specific, prior written permission. 22*d19ef5a2SAaron LI * 23*d19ef5a2SAaron LI * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24*d19ef5a2SAaron LI * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25*d19ef5a2SAaron LI * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 26*d19ef5a2SAaron LI * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 27*d19ef5a2SAaron LI * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 28*d19ef5a2SAaron LI * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 29*d19ef5a2SAaron LI * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30*d19ef5a2SAaron LI * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 31*d19ef5a2SAaron LI * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32*d19ef5a2SAaron LI * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 33*d19ef5a2SAaron LI * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34*d19ef5a2SAaron LI * SUCH DAMAGE. 35*d19ef5a2SAaron LI */ 36*d19ef5a2SAaron LI 37*d19ef5a2SAaron LI #ifndef CHINESE_H_ 38*d19ef5a2SAaron LI #define CHINESE_H_ 39*d19ef5a2SAaron LI 40*d19ef5a2SAaron LI #include <stdbool.h> 41*d19ef5a2SAaron LI 42*d19ef5a2SAaron LI struct chinese_date { 43*d19ef5a2SAaron LI int cycle; 44*d19ef5a2SAaron LI int year; /* year in the $cycle: [1, 60] */ 45*d19ef5a2SAaron LI int month; /* [1, 12] */ 46*d19ef5a2SAaron LI bool leap; /* whether $month is a leap month */ 47*d19ef5a2SAaron LI int day; 48*d19ef5a2SAaron LI }; 49*d19ef5a2SAaron LI 50*d19ef5a2SAaron LI struct chinese_jieqi { 51*d19ef5a2SAaron LI const char *name; 52*d19ef5a2SAaron LI const char *zhname; 53*d19ef5a2SAaron LI bool is_major; /* whether a major solar term (Zhōngqì) */ 54*d19ef5a2SAaron LI int longitude; /* longitude of Sun */ 55*d19ef5a2SAaron LI }; 56*d19ef5a2SAaron LI 57*d19ef5a2SAaron LI enum { C_JIEQI_ALL, C_JIEQI_MAJOR, C_JIEQI_MINOR }; 58*d19ef5a2SAaron LI 59*d19ef5a2SAaron LI struct cal_day; 60*d19ef5a2SAaron LI 61*d19ef5a2SAaron LI int chinese_new_year(int year); 62*d19ef5a2SAaron LI 63*d19ef5a2SAaron LI void chinese_from_fixed(int rd, struct chinese_date *date); 64*d19ef5a2SAaron LI int fixed_from_chinese(const struct chinese_date *date); 65*d19ef5a2SAaron LI 66*d19ef5a2SAaron LI int chinese_qingming(int g_year); 67*d19ef5a2SAaron LI int chinese_jieqi_onafter(int rd, int type, const struct chinese_jieqi **jieqi); 68*d19ef5a2SAaron LI 69*d19ef5a2SAaron LI int chinese_format_date(char *buf, size_t size, int rd); 70*d19ef5a2SAaron LI int chinese_find_days_ymd(int year, int month, int day, struct cal_day **dayp, 71*d19ef5a2SAaron LI char **edp); 72*d19ef5a2SAaron LI int chinese_find_days_dom(int dom, struct cal_day **dayp, char **edp); 73*d19ef5a2SAaron LI void show_chinese_calendar(int rd); 74*d19ef5a2SAaron LI 75*d19ef5a2SAaron LI #endif 76