### Install Python Package Source: https://github.com/yuangu/sxtwl_cpp/blob/master/doc/如何构建.md Command to install the Python wrapper for the project by executing the setup script in the root directory. ```bash python setup.py install ``` -------------------------------- ### Installation Source: https://github.com/yuangu/sxtwl_cpp/blob/master/python/README.md Instructions on how to install the sxtwl library using pip, including how to install a specific version for compatibility. ```APIDOC ## Installation ### Description Instructions on how to install the sxtwl library using pip, including how to install a specific version for compatibility. ### Method pip ### Endpoint N/A ### Parameters #### Query Parameters - **version** (string) - Optional - Specify a version, e.g., `sxtwl==1.1.0` ### Request Example ```bash pip install sxtwl ``` ### Response #### Success Response (200) Installation successful. #### Response Example ``` Successfully installed sxtwl-x.x.x ``` ``` -------------------------------- ### Install sxtwl via pip Source: https://github.com/yuangu/sxtwl_cpp/blob/master/python/README.md Instructions for installing the sxtwl library using pip, including version-specific compatibility for older projects. ```bash pip install sxtwl # For V1.x compatibility pip install sxtwl==1.1.0 ``` -------------------------------- ### Build Project via CMake Command Line Source: https://github.com/yuangu/sxtwl_cpp/blob/master/doc/如何构建.md Standard procedure to build the project using CMake command-line tools. It creates a build directory, configures the project with example support, and executes the build. ```bash mkdir build cd build cmake .. -DSXTWL_BUILD_EXAMPLES=1 cmake --build . ``` -------------------------------- ### Install SXTWL Python Package Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Instructions for installing the SXTWL library for Python using pip. This is the primary method for accessing the library's functionalities in Python environments. ```bash pip install sxtwl ``` -------------------------------- ### Date Navigation: After and Before Source: https://github.com/yuangu/sxtwl_cpp/blob/master/python/README.md Explains how to get information for days preceding or following a given day. ```APIDOC ## Date Navigation: After and Before ### Description Explains how to get information for days preceding or following a given day. ### Method Python ### Endpoint N/A ### Parameters - **day** (object) - Required - A day object. - **num** (integer) - Required - The number of days to move forward (positive) or backward (negative). ### Request Example ```python import sxtwl # Assuming 'day' is an existing day object num = 1 # Get the day after the current day day_after = day.after(num) solar_info_after = f"公历:{day_after.getSolarYear()}年{day_after.getSolarMonth()}月{day_after.getSolarDay()}日" print(f"{num}天后的日期: {solar_info_after}") # Get the day before the current day day_before = day.before(num) solar_info_before = f"公历:{day_before.getSolarYear()}年{day_before.getSolarMonth()}月{day_before.getSolarDay()}日" print(f"{num}天前的日期: {solar_info_before}") ``` ### Response #### Success Response (200) New day objects representing the future or past dates are returned. #### Response Example ``` 1天后的日期: 2021年11月8日 1天前的日期: 2021年11月6日 ``` ``` -------------------------------- ### Get Celestial Stems and Branches (Python) Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Shows how to retrieve the Celestial Stems and Branches (天干地支) for the year, month, day, and hour using methods like `getYearGZ`, `getMonthGZ`, `getDayGZ`, and `getHourGZ`. It supports different calculation bases for the year (e.g., based on the start of spring or Chinese New Year). ```python import sxtwl Gan = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"] Zhi = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"] ShX = ["鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"] day = sxtwl.fromSolar(2024, 2, 10) # Year GZ based on the start of spring (default, for fortune-telling) yTG = day.getYearGZ() print(f"以立春为界的年干支: {Gan[yTG.tg]}{Zhi[yTG.dz]}") print(f"生肖: {ShX[yTG.dz]}") # Expected Output: 以立春为界的年干支: 甲辰 # Expected Output: 生肖: 龙 # Year GZ based on Chinese New Year (pass True) yTG_cny = day.getYearGZ(True) print(f"以春节为界的年干支: {Gan[yTG_cny.tg]}{Zhi[yTG_cny.dz]}") # Expected Output: 以春节为界的年干支: 甲辰 # Month GZ mTG = day.getMonthGZ() print(f"月干支: {Gan[mTG.tg]}{Zhi[mTG.dz]}") # Expected Output: 月干支: 丙寅 # Day GZ dTG = day.getDayGZ() print(f"日干支: {Gan[dTG.tg]}{Zhi[dTG.dz]}") # Expected Output: 日干支: 甲辰 # Hour GZ (pass 24-hour format hour) hour = 14 sTG = day.getHourGZ(hour) print(f"{hour}时的干支: {Gan[sTG.tg]}{Zhi[sTG.dz]}") # Expected Output: 14时的干支: 辛未 # Hour GZ without early/late Zi hour split (23:00 is not split) sTG_no_split = day.getHourGZ(23, False) print(f"23时的干支(非早晚子时): {Gan[sTG_no_split.tg]}{Zhi[sTG_no_split.dz]}") ``` -------------------------------- ### Query Solar Terms (Python) Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Provides examples of checking if a given day is a solar term using `hasJieQi`, retrieving the index of the solar term with `getJieQi`, and obtaining its precise time in Julian Day format using `getJieQiJD`. The Julian Day can then be converted to a date and time. ```python import sxtwl jqmc = ["冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪"] day = sxtwl.fromSolar(2024, 2, 4) # Feb 4, 2024, is Lichun (Start of Spring) # Check if the day has a solar term if day.hasJieQi(): # Get the index of the solar term jq_index = day.getJieQi() print(f"节气: {jqmc[jq_index]}") # Expected Output: 节气: 立春 # Get the precise time of the solar term in Julian Day (JD) jd = day.getJieQiJD() # Convert JD to Year, Month, Day, Hour, Minute, Second t = sxtwl.JD2DD(jd) print(f"节气时间: {t.Y}-{t.M}-{t.D} {int(t.h)}:{int(t.m)}:{round(t.s)}") # Expected Output: 节气时间: 2024-2-4 16:26:53 else: print("当天不是节气日") ``` -------------------------------- ### C++ Date and Solar Term Calculation with SXTWL Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt This C++ example demonstrates how to use the SXTWL library to create a Day object from a Gregorian date, retrieve Gregorian and Lunar calendar information, calculate celestial stems and branches for year, month, and day, check for and retrieve solar term details, list all solar terms for a year, and determine if there is a leap month. It includes necessary headers and defines constants for Chinese calendar terms. ```cpp #include #include "sxtwl.h" #include "const.h" // 常量定义 static const char *Gan[] = {"甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"}; static const char *Zhi[] = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}; static const char *jqmc[] = {"冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪"}; int main() { // 从公历创建Day对象 Day* day = sxtwl::fromSolar(2024, 2, 10); // 获取公历日期 std::cout << "公历: " << day->getSolarYear() << "年" << (int)day->getSolarMonth() << "月" << day->getSolarDay() << "日" << std::endl; // 获取农历日期 std::cout << "农历: " << day->getLunarYear() << "年" << (int)day->getLunarMonth() << "月" << day->getLunarDay() << "日" << std::endl; // 获取干支 GZ yearGZ = day->getYearGZ(); GZ monthGZ = day->getMonthGZ(); GZ dayGZ = day->getDayGZ(); std::cout << "年干支: " << Gan[yearGZ.tg] << Zhi[yearGZ.dz] << std::endl; std::cout << "月干支: " << Gan[monthGZ.tg] << Zhi[monthGZ.dz] << std::endl; std::cout << "日干支: " << Gan[dayGZ.tg] << Zhi[dayGZ.dz] << std::endl; // 检查节气 if (day->hasJieQi()) { double jd = day->getJieQiJD(); Time t = sxtwl::JD2DD(jd); std::cout << "节气: " << jqmc[day->getJieQi()] << " 时间: " << t.getYear() << "-" << t.getMonth() << "-" << t.getDay() << " " << (int)t.getHour() << ":" << (int)t.getMin() << std::endl; } // 获取一年的节气 auto jieqiList = sxtwl::getJieQiByYear(2024); for (auto& jq : jieqiList) { Time t = sxtwl::JD2DD(jq.jd); std::cout << jqmc[jq.jqIndex] << ": " << t.getYear() << "-" << t.getMonth() << "-" << t.getDay() << std::endl; } // 获取闰月 uint8_t runMonth = sxtwl::getRunMonth(2024); if (runMonth > 0) { std::cout << "2024年闰" << (int)runMonth << "月" << std::endl; } delete day; return 0; } ``` -------------------------------- ### Get All Solar Terms for a Year (Python) Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Demonstrates how to efficiently retrieve all solar terms for a given year using `sxtwl.getJieQiByYear`. The function returns a list of objects, each containing the solar term index and its precise Julian Day time, which can be converted to human-readable format. ```python import sxtwl jqmc = ["冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪"] # Get all solar terms for the year 2024 jieqi_list = sxtwl.getJieQiByYear(2024) for jq in jieqi_list: t = sxtwl.JD2DD(jq.jd) print(f"{jqmc[jq.jqIndex]}: {t.Y}-{t.M}-{t.D} {int(t.h)}:{int(t.m)}:{round(t.s)}") # Expected Output: # 立春: 2024-2-4 16:26:53 # 雨水: 2024-2-19 12:12:58 # 惊蛰: 2024-3-5 10:22:31 # 春分: 2024-3-20 11:6:12 # ... ``` -------------------------------- ### Configure Go Wrapper Source: https://github.com/yuangu/sxtwl_cpp/blob/master/CMakeLists.txt Configures the build for Go bindings, generating a static library for the wrapper. ```cmake if(SXTWL_WRAPPER_GO) include_directories("./src") add_library(sxtwl_go STATIC "./export/golang/sxtwl_wrap.cxx") target_link_libraries(sxtwl_go sxtwl) endif(SXTWL_WRAPPER_GO) ``` -------------------------------- ### Basic Usage: Importing and Creating Day Objects Source: https://github.com/yuangu/sxtwl_cpp/blob/master/python/README.md Demonstrates how to import the sxtwl library and create day objects from both solar and lunar dates. ```APIDOC ## Basic Usage: Importing and Creating Day Objects ### Description Demonstrates how to import the sxtwl library and create day objects from both solar and lunar dates. ### Method Python ### Endpoint N/A ### Parameters N/A ### Request Example ```python import sxtwl # Create a day object from a solar date day_solar = sxtwl.fromSolar(2021, 11, 7) # Create a day object from a lunar date day_lunar = sxtwl.fromLunar(2020, 12, 1) ``` ### Response #### Success Response (200) Day objects are created successfully. #### Response Example ```python # day_solar and day_lunar objects are now available for use ``` ``` -------------------------------- ### Build for iOS Platform Source: https://github.com/yuangu/sxtwl_cpp/blob/master/doc/如何构建.md Command-line instructions to configure and build the project for iOS using the Xcode generator. ```bash cd build cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/ios.cmake \ -DIOS_PLATFORM=OS \ -DCMAKE_BUILD_TYPE=Release \ -GXcode cmake --build . ``` -------------------------------- ### Configure C# Wrapper Source: https://github.com/yuangu/sxtwl_cpp/blob/master/CMakeLists.txt Configures the build for C# bindings by including the source directory and linking the generated wrapper library. ```cmake if(SXTWL_WRAPPER_CSHARP) include_directories( "./src") add_library(sxtwl_csharp SHARED "./export/C#/sxtwl_wrap.cxx") target_link_libraries(sxtwl_csharp sxtwl) endif(SXTWL_WRAPPER_CSHARP) ``` -------------------------------- ### Clone sxtwl_cpp Repository Source: https://github.com/yuangu/sxtwl_cpp/blob/master/doc/如何构建.md Command to download the source code from the official GitHub repository using Git. ```bash git clone https://github.com/yuangu/sxtwl_cpp.git ``` -------------------------------- ### Configure PHP Wrappers Source: https://github.com/yuangu/sxtwl_cpp/blob/master/CMakeLists.txt Configures the build for PHP 5 and PHP 7 bindings. It uses a custom FindPHP module to locate headers and link the wrapper library. ```cmake if(SXTWL_WRAPPER_PHP5) include(${CMAKE_SOURCE_DIR}/cmake/FindPHP.cmake) include_directories(${PHP_INCLUDE_DIRS} ${PHP_EXTENSIONS_INCLUDE_DIR} "./src") add_library(sxtwl_php5 SHARED "./export/php5/sxtwl_wrap.cxx") target_link_libraries(sxtwl_php5 sxtwl) endif(SXTWL_WRAPPER_PHP5) ``` -------------------------------- ### CMake Build Configuration for sxtwl_c Source: https://github.com/yuangu/sxtwl_cpp/blob/master/c/CMakeLists.txt This CMake script sets up the build environment for the sxtwl_c project. It specifies the minimum CMake version, project name, include directories, C++ and C standards, and platform-specific compiler flags for Windows. It dynamically finds source files and defines the build target as either an executable or a static library depending on the EMSCRIPTEN flag, linking against the 'sxtwl' library. ```cmake cmake_minimum_required(VERSION 3.6) project(sxtwl_c) include_directories("../src") set(CMAKE_CXX_STANDARD 11) set(CMAKE_C_STANDARD 11) IF(${CMAKE_SYSTEM_NAME} STREQUAL "Windows") ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS) add_compile_options("$<$:/utf-8>") add_compile_options("$<$:/utf-8>") ENDIF() file(GLOB SRC_FILES *.cpp *.c ) IF (EMSCRIPTEN) add_executable(sxtwl_c ${SRC_FILES}) target_link_libraries(sxtwl_c sxtwl) ELSE(EMSCRIPTEN) add_library(sxtwl_c STATIC ${SRC_FILES}) target_link_libraries(sxtwl_c sxtwl) ENDIF(EMSCRIPTEN) ``` -------------------------------- ### Perform Date Arithmetic and Conversions Source: https://github.com/yuangu/sxtwl_cpp/blob/master/python/README.md Shows how to calculate dates before or after a given day, find leap months, and convert between Julian dates and standard calendar dates. ```python # Get date after 1 day day = day.after(1) # Get leap month for a year month = sxtwl.getRunMonth(2020) # Julian date conversion jd = sxtwl.toJD(t) ``` -------------------------------- ### Build Android Project Independently Source: https://github.com/yuangu/sxtwl_cpp/blob/master/doc/如何构建.md Advanced shell script to configure and build the project for Android using the NDK toolchain and Ninja build system. ```bash set ANDROID_SDK=D:/android/sdk set ANDROID_NDK=D:/android/android-ndk-r14b set ANDROID_ABI=armeabi set ANDROID_CMAKE=%ANDROID_SDK%/cmake/3.6.4111459/bin/cmake.exe set ANDROID_NINJA=%ANDROID_SDK%/cmake/3.6.4111459/bin/ninja.exe %ANDROID_CMAKE% -DANDROID_ABI=%ANDROID_ABI% \ -DANDROID_PLATFORM=android-16 \ -DCMAKE_BUILD_TYPE=Release \ -DANDROID_NDK=%ANDROID_NDK% \ -DCMAKE_CXX_FLAGS=-std=c++11 -frtti -fexceptions \ -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK%/build/cmake/android.toolchain.cmake \ -DCMAKE_MAKE_PROGRAM=%ANDROID_NINJA% -G "Ninja" \ -DCONSOLE=1 \ -DSXTWL_WRAPPER_JAVA=1 .. %ANDROID_CMAKE% --build . ``` -------------------------------- ### Initialize Calendar Data Index Source: https://github.com/yuangu/sxtwl_cpp/blob/master/python/README.md Defines the necessary arrays for mapping calendar data like Gan-Zhi, zodiac signs, and solar terms to human-readable strings. ```python Gan = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"] Zhi = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"] ShX = ["鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"] jqmc = ["冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪"] ``` -------------------------------- ### Query Date Information Source: https://github.com/yuangu/sxtwl_cpp/blob/master/python/README.md Demonstrates how to retrieve calendar details such as solar/lunar dates, week index, and Gan-Zhi from a specific date. ```python import sxtwl day = sxtwl.fromSolar(2021, 11, 7) print("公历:%d年%d月%d日" % (day.getSolarYear(), day.getSolarMonth(), day.getSolarDay())) print("农历:%d年%s%d月%d日" % (day.getLunarYear(), '闰' if day.isLunarLeap() else '', day.getLunarMonth(), day.getLunarDay())) ``` -------------------------------- ### Configure Lua Wrapper Source: https://github.com/yuangu/sxtwl_cpp/blob/master/CMakeLists.txt Configures the build for Lua bindings. It verifies the presence of the Lua development package and links the wrapper library. ```cmake if(SXTWL_WRAPPER_LUA) find_package(Lua) if(${LUA_FOUND}) message(STATUS "lua Found") else(${LUA_FOUND}) message(FATAL_ERROR "not found lua") endif() include_directories(${LUA_INCLUDE_DIR} "./src") add_library(sxtwl_lua SHARED "./export/lua/sxtwl_wrap.cxx") target_link_libraries(sxtwl_lua sxtwl ${LUA_LIBRARIES}) endif(SXTWL_WRAPPER_LUA) ``` -------------------------------- ### Create Day Object from Solar Date (Python) Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Demonstrates how to create a Day object from a Gregorian calendar date (year, month, day) using `sxtwl.fromSolar`. This object allows retrieval of various calendar information including lunar details, celestial stems, and branches. ```python import sxtwl # Constants for Chinese calendar elements Gan = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"] Zhi = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"] ShX = ["鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"] ymc = ["正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"] rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五", "十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"] # Create a Day object from solar date day = sxtwl.fromSolar(2024, 2, 10) # Get solar calendar information print(f"公历: {day.getSolarYear()}年{day.getSolarMonth()}月{day.getSolarDay()}日") # Expected Output: 公历: 2024年2月10日 # Get lunar calendar information lunar_month = "闰" if day.isLunarLeap() else "" print(f"农历: {day.getLunarYear()}年{lunar_month}{ymc[day.getLunarMonth()-1]}月{rmc[day.getLunarDay()-1]}") # Expected Output: 农历: 2024年正月初一 ``` -------------------------------- ### Date Arithmetic and Solar Term Tracking Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Illustrates how to move dates forward or backward by a specific number of days and how to iterate through dates to find the next solar term. ```python import sxtwl day = sxtwl.fromSolar(2024, 2, 10) # Move dates day_after = day.after(10) # Find next solar term current = sxtwl.fromSolar(2024, 2, 10) while True: current = current.after(1) if current.hasJieQi(): print(f"Next solar term: {current.getJieQi()}") break ``` -------------------------------- ### Create Day Object from Lunar Date (Python) Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Demonstrates creating a Day object from a Chinese lunisolar calendar date (year, month, day) using `sxtwl.fromLunar`. It also shows how to specify whether the month is a leap month by passing a boolean argument. ```python import sxtwl # Create a Day object from lunar date (2024, 1, 1) day = sxtwl.fromLunar(2024, 1, 1) # Convert to Gregorian calendar date print(f"公历: {day.getSolarYear()}年{day.getSolarMonth()}月{day.getSolarDay()}日") # Expected Output: 公历: 2024年2月10日 # Query leap month information (e.g., leap 4th month of 2020) day_leap = sxtwl.fromLunar(2020, 4, 1, True) # True indicates a leap month print(f"公历: {day_leap.getSolarYear()}年{day_leap.getSolarMonth()}月{day_leap.getSolarDay()}日") # Expected Output: 公历: 2020年5月23日 # Non-leap month (e.g., 4th month of 2020) day_normal = sxtwl.fromLunar(2020, 4, 1, False) print(f"公历: {day_normal.getSolarYear()}年{day_normal.getSolarMonth()}月{day_normal.getSolarDay()}日") # Expected Output: 公历: 2020年4月23日 ``` -------------------------------- ### Query Leap Months and Lunar Month Lengths Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Demonstrates how to identify leap months within a range of years and calculate the total number of days in a specific lunar month, accounting for leap months. ```python import sxtwl # Batch query leap months for y in range(2020, 2030): m = sxtwl.getRunMonth(y) if m > 0: print(f"{y}年闰{m}月") # Get days in a lunar month year, month, isRun = 2024, 1, False daynum = sxtwl.getLunarMonthNum(year, month, isRun) print(f"农历{year}年{month}月共{daynum}天") ``` -------------------------------- ### Julian Date and Gregorian Date Conversions Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Shows how to convert between Julian Days (JD) and Gregorian calendar dates, including calculating the difference between two dates. ```python import sxtwl # JD to Gregorian jd = sxtwl.J2000 t = sxtwl.JD2DD(jd) print(f"J2000: {t.Y}-{t.M}-{t.D}") # Gregorian to JD time = sxtwl.Time(2024, 2, 10, 12, 0, 0) jd = sxtwl.toJD(time) # Calculate difference t1 = sxtwl.Time(2024, 2, 10, 0, 0, 0) t2 = sxtwl.Time(2024, 3, 10, 0, 0, 0) diff = sxtwl.toJD(t2) - sxtwl.toJD(t1) print(f"相差{int(diff)}天") ``` -------------------------------- ### Configure Java JNI Wrapper Source: https://github.com/yuangu/sxtwl_cpp/blob/master/CMakeLists.txt Configures the build for Java JNI bindings. It checks for JNI availability (or Android environment) and links the generated wrapper library against the core SXTWL library. ```cmake if(SXTWL_WRAPPER_JAVA) IF(ANDROID) message(STATUS "Android Jni") ELSE(ANDROID) find_package(JNI) if(${JNI_FOUND}) message(STATUS "Jni Found") else(${JNI_FOUND}) message(FATAL_ERROR "not found Jni") endif() endif(ANDROID) include_directories(${JNI_INCLUDE_DIRS} "./src") add_library(sxtwl_java SHARED "./export/java/sxtwl_wrap.cxx") target_link_libraries(sxtwl_java sxtwl ${JNI_LIBRARIES}) endif(SXTWL_WRAPPER_JAVA) ``` -------------------------------- ### Finding Solar Terms Before or After a Date Source: https://github.com/yuangu/sxtwl_cpp/blob/master/python/README.md Demonstrates how to find the next or previous solar term relative to a given date. ```APIDOC ## Finding Solar Terms Before or After a Date ### Description Demonstrates how to find the next or previous solar term relative to a given date. ### Method Python ### Endpoint N/A ### Parameters - **day** (object) - Required - The starting day object. ### Request Example ```python import sxtwl # Assuming 'day' is an existing day object jqmc = ["冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪"] # Find the next solar term current_day = day while True: current_day = current_day.after(1) if current_day.hasJieQi(): jieqi_name = jqmc[current_day.getJieQi()] jd = current_day.getJieQiJD() t = sxtwl.JD2DD(jd) print(f"Next solar term: {jieqi_name} at {t.Y}-{t.M}-{t.D} {t.h}:{t.m}:{round(t.s)}") break # Find the previous solar term (example, replace 'after' with 'before' if needed) current_day = day while True: current_day = current_day.before(1) # Use .before(1) to go backwards if current_day.hasJieQi(): jieqi_name = jqmc[current_day.getJieQi()] jd = current_day.getJieQiJD() t = sxtwl.JD2DD(jd) print(f"Previous solar term: {jieqi_name} at {t.Y}-{t.M}-{t.D} {t.h}:{t.m}:{round(t.s)}") break ``` ### Response #### Success Response (200) Information about the found solar terms is printed. #### Response Example ``` Next solar term: 小寒 at 2022-1-5 22:37:0 Previous solar term: 大寒 at 2022-1-20 9:50:0 ``` ``` -------------------------------- ### Calculate Hour GZ Independently (Python) Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Demonstrates the standalone function `sxtwl.getShiGz` for calculating the Celestial Stems and Branches for a specific hour. This function can be used without a `Day` object, requiring only the day's stem index and the hour. ```python import sxtwl Gan = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"] Zhi = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"] day = sxtwl.fromSolar(2024, 2, 10) dayTG = day.getDayGZ() # Iterate through all hours of the day to get their GZ for hour in range(24): hTG = sxtwl.getShiGz(dayTG.tg, hour) print(f"{hour}时: {Gan[hTG.tg]}{Zhi[hTG.dz]}") # Expected Output: # 0时: 甲子 # 1时: 甲子 # 2时: 乙丑 # 3时: 乙丑 # ... # 23时: 乙丑 # Calculate GZ for 23:00 without splitting early/late Zi hour (default is True) hTG = sxtwl.getShiGz(dayTG.tg, 23, False) ``` -------------------------------- ### Retrieving Day Information Source: https://github.com/yuangu/sxtwl_cpp/blob/master/python/README.md Shows how to extract various pieces of information from a day object, including solar/lunar dates, celestial stems and branches, and solar terms. ```APIDOC ## Retrieving Day Information ### Description Shows how to extract various pieces of information from a day object, including solar/lunar dates, celestial stems and branches, and solar terms. ### Method Python ### Endpoint N/A ### Parameters - **day** (object) - Required - A day object created using `sxtwl.fromSolar` or `sxtwl.fromLunar`. ### Request Example ```python import sxtwl # Assuming 'day' is a day object obtained from sxtwl.fromSolar or sxtwl.fromLunar # Solar date solar_info = f"公历:{day.getSolarYear()}年{day.getSolarMonth()}月{day.getSolarDay()}日" print(solar_info) # Weekday weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"] print(weekdays[day.getWeek()]) # Week of the month print(f'该日属于这个月的第{day.getWeekIndex()}周') # Zodiac sign (Note: May have bugs, needs verification) xi_zodiac = ['摩羯', '水瓶', '双鱼', '白羊', '金牛', '双子', '巨蟹', '狮子', '处女', '天秤', '天蝎', '射手'] print("星座:", xi_zodiac[day.getConstellation()]) # Lunar date (based on Spring Festival) lunar_year_spring = day.getLunarYear() lunar_month_spring = day.getLunarMonth() lunar_day_spring = day.getLunarDay() is_leap_spring = day.isLunarLeap() lunar_info_spring = f"农历(春节为界):{lunar_year_spring}年{'闰' if is_leap_spring else ''}{lunar_month_spring}月{lunar_day_spring}日" print(lunar_info_spring) # Lunar date (based on Start of Spring) lunar_year_spring_start = day.getLunarYear(False) lunar_info_spring_start = f"农历(立春为界):{lunar_year_spring_start}年{'闰' if is_leap_spring else ''}{lunar_month_spring}月{lunar_day_spring}日" print(lunar_info_spring_start) # Celestial stems and branches for the year (based on Spring Festival) yTG_spring = day.getYearGZ(True) gan = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"] zhi = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"] shx = ["鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪"] print("以春节为界的年干支", gan[yTG_spring.tg] + zhi[yTG_spring.dz]) print("以春节为界的生肖:", shx[yTG_spring.dz]) # Celestial stems and branches for the year (based on Start of Spring) yTG_start = day.getYearGZ() print("以立春为界的年干支", gan[yTG_start.tg] + zhi[yTG_start.dz]) print("以立春为界的生肖:", shx[yTG_start.dz]) # Celestial stems and branches for the month mTG = day.getMonthGZ() print("月干支", gan[mTG.tg] + zhi[mTG.dz]) # Celestial stems and branches for the day dTG = day.getDayGZ() print("日干支", gan[dTG.tg] + zhi[dTG.dz]) # Celestial stems and branches for the hour (24-hour format) hour = 18 sTG = day.getHourGZ(hour) print(f"{hour}时的干支", gan[sTG.tg] + zhi[sTG.dz]) # Celestial stems and branches for each hour of the day for hour in range(24): hTG = sxtwl.getShiGz(dTG.tg, hour) print(f"{hour}时天干地支:", gan[hTG.tg] + zhi[hTG.dz]) # Check for solar terms jqmc = ["冬至", "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪"] if day.hasJieQi(): print('节气:%s'% jqmc[day.getJieQi()]) # Get Julian day number of the solar term jd = day.getJieQiJD() # Convert Julian day number to date and time t = sxtwl.JD2DD(jd) print(f"节气时间:{t.Y}-{t.M}-{t.D} {t.h}:{t.m}:{round(t.s)}") else: print("当天不是节气日") ``` ### Response #### Success Response (200) Information is printed to the console. #### Response Example ``` 公历:2021年11月7日 星期日 该日属于这个月的第2周 星座: 天蝎座 农历(春节为界):2021年九月廿三日 农历(立春为界):2021年九月廿三日 以春节为界的年干支 辛丑 以春节为界的生肖: 牛 以立春为界的年干支 辛丑 以立春为界的生肖: 牛 月干支 壬戌 日干支 辛亥 18时的干支 壬戌 0时天干地支: 辛亥 1时天干地支: 辛亥 ... (output for all 24 hours) 节气:立冬 节气时间:2021-11-7 11:00:0 ``` ``` -------------------------------- ### Query Leap Month Information (Python) Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Shows how to use `sxtwl.getRunMonth` to determine if a given Gregorian year has a leap month in the Chinese lunisolar calendar and, if so, which month it is. Returns 0 if there is no leap month. ```python import sxtwl # Get the leap month for the year 2020 year = 2020 month = sxtwl.getRunMonth(year) if month > 0: print(f"{year}年闰{month}月") # Expected Output: 2020年闰4月 else: print(f"{year}年无闰月") ``` -------------------------------- ### Date Conversion and Calendar API Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Functions to convert solar dates to lunar dates, retrieve Gan-Zhi, and calculate solar terms. ```APIDOC ## [FUNCTION] sxtwl::fromSolar ### Description Creates a Day object from a given Gregorian calendar date. ### Method Static Factory Method ### Parameters #### Arguments - **year** (int) - Required - Gregorian year - **month** (int) - Required - Gregorian month - **day** (int) - Required - Gregorian day ### Response - **Day*** - Pointer to a Day object containing solar/lunar data and Gan-Zhi information. ## [FUNCTION] sxtwl::getJieQiByYear ### Description Retrieves a list of all solar terms for a specific year. ### Method Static Method ### Parameters #### Arguments - **year** (int) - Required - The year to query ### Response - **std::vector** - A list of solar term objects containing the index and Julian Date (jd). ``` -------------------------------- ### Map Gan-Zhi String to SXTWL Object Source: https://github.com/yuangu/sxtwl_cpp/blob/master/python/README.md Converts a two-character Gan-Zhi string into an SXTWL GZ object. It iterates through predefined Gan and Zhi lists to find the corresponding numerical indices. ```python def getGZ(gzStr): tg = -1 dz = -1 for i, v in enumerate(Gan): if gzStr[0] == v: tg = i break for i, v in enumerate(Zhi): if gzStr[1] == v: dz = i break return sxtwl.GZ(tg, dz) ``` -------------------------------- ### Load Native Library in Android Source: https://github.com/yuangu/sxtwl_cpp/blob/master/doc/如何构建.md Java code snippet required to load the compiled native library within an Android application. ```java System.loadLibrary("sxtwl_java"); ``` -------------------------------- ### Retrieve Weekday and Constellation Information Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Extracts the day of the week, the week index within the month, and the zodiac constellation for a given solar date. ```python import sxtwl day = sxtwl.fromSolar(2024, 2, 10) print(f"Weekday: {day.getWeek()}") print(f"Week index: {day.getWeekIndex()}") print(f"Constellation: {day.getConstellation()}") ``` -------------------------------- ### Four Pillars (SiZhu) Reverse Lookup Source: https://context7.com/yuangu/sxtwl_cpp/llms.txt Finds Gregorian dates that match a specific set of Four Pillars (Year, Month, Day, Hour stems and branches) within a given year range. ```python import sxtwl # Search for specific GanZhi combination jds = sxtwl.siZhu2Year(sxtwl.GZ(0, 4), sxtwl.GZ(2, 2), sxtwl.GZ(0, 4), sxtwl.GZ(0, 0), 2024, 2025) for jd in jds: t = sxtwl.JD2DD(jd) print(f"Match: {t.Y}-{t.M}-{t.D}") ```