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);

使用给定的格式来输出字符串。类似于strftime的用法。可使用的格式及输出如下:

%(YEAR)年%(MONTH)月%(DAY)日%(HOUR)时 公历:大写->二OO八年一月二十一日

%(year)年%(month)月%(day)日%(hour)时 公历:小写->2008年1月21日

%(NIAN)年%(YUE)月%(RI)%(SHI)时 农历:大写->丁亥年腊月十四己酉时,(月份前带"闰"表示闰月)

%(nian)年%(yue)月%(ri)日%(shi)时 农历:小写->2007年12月14日,(月份前带"*"表示闰月)

%(Y60)年%(M60)月%(D60)日%(H60)时 干支:大写->丁亥年癸丑月庚申日

%(Y8)年%(M8)月%(D8)日%(H8)时 八字:大写->丁亥年癸丑月庚申日

%(shengxiao) 生肖:猪

%(holiday) 节日(节日、纪念日、节气等):立春

使用%(holiday)时,输出会自动截断为3个utf8字符或4个ascii字符,如果需要全部的节日信息,请使用 lunar_date_get_holiday() 得到输出。

Parameters

date

a LunarDate

 

format

specify the output format.

 

Returns

a newly-allocated output string, nul-terminated

Since: 2.4.0


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_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.