CelestialCalendar 1.0.0 · unreleased development @ 67a7c4c79a4a4a6aa7e703c9e6f0039ae34bee82
Loading...
Searching...
No Matches
calendar::lunar::converter::Converter< algo > Struct Template Reference

Converts between gregorian date and lunar date. 将公历日期和阴历日期进行转换。 More...

#include <converter.hpp>

Public Types

using AlgoMetadata

Static Public Member Functions

static auto is_valid_gregorian (const year_month_day &date) -> bool
 Checks if the input gregorian date is valid and within the supported range. 检查输入的公历日期是否有效,且在支持的范围内。
static auto is_valid_lunar (const year_month_day &lunar_date) -> bool
 Checks if the input lunar date is valid and within the supported range. 检查输入的阴历日期是否有效,且在支持的范围内。
static auto gregorian_to_lunar (const year_month_day &gregorian_date) -> std::optional< year_month_day >
 Converts gregorian date to lunar date. 将公历日期转换为阴历日期。
static auto lunar_to_gregorian (const year_month_day &lunar_date) -> std::optional< year_month_day >
 Converts lunar date to gregorian date. 将阴历日期转换为公历日期。

Detailed Description

template<common::Algo algo>
struct calendar::lunar::converter::Converter< algo >

Converts between gregorian date and lunar date. 将公历日期和阴历日期进行转换。

Template Parameters
algoThe algorithm to use. 使用的算法。
Note
Lunar months are positional in this interface: the month of a lunar year_month_day is the 1-based index into the year's month sequence (12 or 13 entries), where a leap month takes its own position — not the traditional month number, which this interface cannot express (there is no leap flag). E.g. lunar 2023 (leap 2nd month): month 3 is the leap 2nd month, and the traditional 3rd month is month 4. Translate with common::month_position / common::month_at_position (#130). 本接口的阴历月是位置序号:阴历 year_month_day 的「月」是该年 12/13 个月里 从 1 起的位置,闰月独占一位——不是传统编号(本接口没有闰月标记,表达不了)。 例:2023 年闰二月,月 3 = 闰二月,传统三月 = 月 4。与传统编号的互转见 common::month_position / common::month_at_position(#130)。
Gregorian inputs and outputs are calendar-date labels on the selected algorithm's basis, not instants. See algo1.hpp, algo2.hpp, and algo3.hpp for their date bases. 公历输入和输出是所选算法基准上的日期标记,不是时刻。 各算法的日期基准见 algo1.hpp、algo2.hpp 和 algo3.hpp。

Member Typedef Documentation

◆ AlgoMetadata

template<common::Algo algo>
using calendar::lunar::converter::Converter< algo >::AlgoMetadata

Member Function Documentation

◆ gregorian_to_lunar()

template<common::Algo algo>
auto calendar::lunar::converter::Converter< algo >::gregorian_to_lunar ( const year_month_day & gregorian_date) ->std::optional< year_month_day >
inlinestaticnodiscard

Converts gregorian date to lunar date. 将公历日期转换为阴历日期。

Parameters
gregorian_dateThe gregorian date. 公历日期。
Returns
The optional lunar date; its month is the positional index (see Converter's note). 阴历日期(optional);其「月」是位置序号(见 Converter 的注)。
Attention
The input date should be in the supported range. 输入的日期需要在所支持的范围内。
std::nullopt is returned if the input date is invalid. No exception is thrown. 输入的日期无效时返回 std::nullopt。不会抛出异常。

◆ is_valid_gregorian()

template<common::Algo algo>
auto calendar::lunar::converter::Converter< algo >::is_valid_gregorian ( const year_month_day & date) ->bool
inlinestaticnodiscard

Checks if the input gregorian date is valid and within the supported range. 检查输入的公历日期是否有效,且在支持的范围内。

Parameters
dateThe date. 公历日期。
Returns
true if valid, otherwise false. 如果有效,返回 true,否则返回 false。

◆ is_valid_lunar()

template<common::Algo algo>
auto calendar::lunar::converter::Converter< algo >::is_valid_lunar ( const year_month_day & lunar_date) ->bool
inlinestaticnodiscard

Checks if the input lunar date is valid and within the supported range. 检查输入的阴历日期是否有效,且在支持的范围内。

Parameters
lunar_dateThe lunar date. 阴历日期。
Returns
true if valid, otherwise false. 如果有效,返回 true,否则返回 false。
Attention
The month is the positional index (see Converter's note): a leap month takes its own position. 月份是位置序号(见 Converter 的注):闰月独占一位。

◆ lunar_to_gregorian()

template<common::Algo algo>
auto calendar::lunar::converter::Converter< algo >::lunar_to_gregorian ( const year_month_day & lunar_date) ->std::optional< year_month_day >
inlinestaticnodiscard

Converts lunar date to gregorian date. 将阴历日期转换为公历日期。

Parameters
lunar_dateThe lunar date; its month is the positional index (see Converter's note). 阴历日期;其「月」是位置序号(见 Converter 的注)。
Returns
The optional gregorian date. 公历日期(optional)。
Attention
The input date should be in the supported range. 输入的日期需要在所支持的范围内。
std::nullopt is returned if the input date is invalid. No exception is thrown. 输入的日期无效时返回 std::nullopt。不会抛出异常。

The documentation for this struct was generated from the following file: