LunarDate

LunarDate — Chinese Lunar Date Library

Stability Level

Stable, unless otherwise indicated

Functions

Types and Values

Object Hierarchy

    GEnum
    ╰── LunarDateError
    GObject
    ╰── LunarDate

Includes

#include <lunar-date/lunar-date.h>

Description

The LunarDate provide Chinese lunar date library.

Functions

lunar_date_error_quark ()

GQuark
lunar_date_error_quark (void);

lunar_date_new ()

LunarDate *
lunar_date_new (void);

Allocates a LunarDate and initializes it. Free the return value with lunar_date_free().

Returns

a newly-allocated LunarDate

Since: 2.4.0


lunar_date_set_solar_date ()

void
lunar_date_set_solar_date (LunarDate *date,
                           GDateYear year,
                           GDateMonth month,
                           GDateDay day,
                           guint8 hour,
                           GError **error);

Sets the solar year, month, day and the hour for a LunarDate.

Parameters

date

a LunarDate.

 

year

year to set.

 

month

month to set.

 

day

day to set.

 

hour

hour to set.

 

error

location to store the error occuring, or NULL to ignore errors.

 

Since: 2.4.0


lunar_date_set_lunar_date ()

void
lunar_date_set_lunar_date (LunarDate *date,
                           GDateYear year,
                           GDateMonth month,
                           GDateDay day,
                           guint8 hour,
                           gboolean isleap,
                           GError **error);

Sets the lunar year, month, day and the hour for a LunarDate. If the month is a leap month, you should set the isleap to TRUE.

Parameters

date

a LunarDate.

 

year

year to set.

 

month

month to set.

 

day

day to set.

 

hour

hour to set.

 

isleap

indicate whether the month is a leap month.

 

error

location to store the error occuring, or NULL to ignore errors.

 

Since: 2.4.0


lunar_date_set_solar_holiday ()

void
lunar_date_set_solar_holiday (LunarDate *date,
                              GDateMonth month,
                              GDateDay day,
                              const gchar *holiday);

Add new holiday by solar.

Parameters

date

a LunarDate

 

month

Solar month of the holiday.

 

day

Solar day of the holiday.

 

holiday

custom holiday string.

 

Since: 3.0.0


lunar_date_set_lunar_holiday ()

void
lunar_date_set_lunar_holiday (LunarDate *date,
                              GDateMonth month,
                              GDateDay day,
                              const gchar *holiday);

Add new holiday by lunar.

Parameters

date

a LunarDate

 

month

Lunar month of the holiday.

 

day

Lunar day of the holiday.

 

holiday

custom holiday string.

 

Since: 3.0.0


lunar_date_set_week_holiday ()

void
lunar_date_set_week_holiday (LunarDate *date,
                             GDateMonth month,
                             gint week_of_month,
                             gint day_of_week,
                             const gchar *holiday);

Add new holiday by week.

Parameters

date

a LunarDate

 

month

Month of the holiday.

 

week_of_month

which week of the month, the first week is 1, range is 1-5.

 

day_of_week

day of the week, 0 for Sunday, 6 for Saturday, range is 0-6.

 

holiday

custom holiday string.

 

Since: 3.0.0


lunar_date_get_holiday ()

gchar *
lunar_date_get_holiday (LunarDate *date,
                        const gchar *delimiter);

Returns the all holiday of the date, joined with the delimiter. The date must be valid.

Parameters

date

a LunarDate

 

delimiter

used to join the holidays.

 

Returns

a newly-allocated holiday string of the date or NULL.

Since: 3.0.0


lunar_date_get_calendar ()

gchar *
lunar_date_get_calendar (LunarDate *date,
                         gint max);

Returns the string about the date, used to show in calendar.

Parameters

date

a LunarDate

 

max

max length of the returned string.

 

Returns

a newly-allocated string of the date or NULL.

Since: 3.0.0


lunar_date_strftime ()

gchar *
lunar_date_strftime (LunarDate *date,
                     const gchar *format);

Use the given format to output a string, similar to strftime usage. The available formats and outputs are as follows:

1
2
3
4
5
6
7
8
format="%(YEAR)年%(MONTH)月%(DAY)日%(HOUR)时", output="一九一○年二月十九日二时"   //大写公历
format="%(year)年%(month)月%(day)日%(hour)时", output="1910年2月19日2时"          //小写公历
format="%(NIAN)年%(YUE)月%(RI)日%(SHI)时",     output="庚戌年一月初十日丑时"      //大写农历(月份前带"闰"表示闰月)
format="%(nian)年%(yue)月%(ri)日%(shi)时",     output="1910年1月10日2时"          //小写农历(月份前带"*"表示闰月)
format="%(Y60)年%(M60)月%(D60)日%(H60)时",     output="庚戌年戊寅月乙卯日丁丑时"  //干支
format="%(Y8)年%(M8)月%(D8)日%(H8)时",         output="庚戌年戊寅月乙卯日丁丑时"  //八字
format="%(shengxiao)",                        output="狗"                         //生肖
format="%(holiday)",                          output="雨水"                       //节日(节日、纪念日、节气等)

When using %(holiday), the output is automatically truncated to 3 utf8 characters or 4 ascii characters. If you need all the holiday information, please use lunar_date_get_holiday() to get the output.

Parameters

date

a LunarDate

 

format

specify the output format.

 

Returns

a newly-allocated output string, nul-terminated

Since: 2.4.0


lunar_date_get_constellation ()

gchar *
lunar_date_get_constellation (LunarDate *date);

lunar_date_free ()

void
lunar_date_free (LunarDate *date);

Frees a LunarDate returned from lunar_date_new().

Parameters

date

a LunarDate

 

Since: 2.4.0


lunar_date_get_jieri ()

gchar *
lunar_date_get_jieri (LunarDate *date,
                      const gchar *delimiter);

lunar_date_get_jieri has been deprecated since version 3.0.0 and should not be used in newly-written code.

Use lunar_date_get_holiday() instead.

Returns the all holiday of the date, joined with the delimiter. The date must be valid.

Parameters

date

a LunarDate

 

delimiter

used to join the holidays.

 

Returns

a newly-allocated holiday string of the date or NULL.

Types and Values

LUNAR_TYPE_DATE

#define LUNAR_TYPE_DATE          (lunar_date_get_type ())

LUNAR_DATE_ERROR

#define LUNAR_DATE_ERROR         (lunar_date_error_quark ())

enum LunarDateError

Members

LUNAR_DATE_ERROR_INTERNAL

internal error.

 

LUNAR_DATE_ERROR_YEAR

year setup error.

 

LUNAR_DATE_ERROR_MONTH

month setup error.

 

LUNAR_DATE_ERROR_DAY

day setup error.

 

LUNAR_DATE_ERROR_HOUR

hour setup error.

 

LUNAR_DATE_ERROR_LEAP

isleap setup error.

 

LunarDate

typedef struct _LunarDate LunarDate;