LunarDate

## LunarDate LunarDate — Translate the date between solar and chinese lunar. |

## Synopsis

    #include <lunar/lunar.h>

    typedef             GDateHour;
                        LunarDate;
    #define             LUNAR_DATE_ERROR
    enum                LunarDateError;
    GQuark              lunar_date_error_quark              (void);
    LunarDate*          lunar_date_new                      (void);
    void                lunar_date_set_solar_date           (LunarDate *date,
                                                             GDateYear year,
                                                             GDateMonth month,
                                                             GDateDay day,
                                                             GDateHour hour,
                                                             GError **error);
    void                lunar_date_set_lunar_date           (LunarDate *date,
                                                             GDateYear year,
                                                             GDateMonth month,
                                                             GDateDay day,
                                                             GDateHour hour,
                                                             gboolean isleap,
                                                             GError **error);
    gchar*              lunar_date_get_jieri                (LunarDate *date);
    gchar*              lunar_date_strftime                 (LunarDate *date,
                                                             const char *format);
    void                lunar_date_free                     (LunarDate *date);

## Description

## Details

### GDateHour

    typedef guint8  GDateHour;

### LunarDate

    typedef struct _LunarDate LunarDate;

The LUNARDate struct contains only private fields and should not be used directly.

### LUNAR_DATE_ERROR

    #define LUNAR_DATE_ERROR	(lunar_date_error_quark ())

### enum LunarDateError

    typedef enum
    {
        LUNAR_DATE_ERROR_INTERNAL,
        LUNAR_DATE_ERROR_DAY,
        LUNAR_DATE_ERROR_YEAR,
        LUNAR_DATE_ERROR_LEAP
    } LunarDateError;

`LUNAR_DATE_ERROR_INTERNAL` | a internal error was found.
`LUNAR_DATE_ERROR_DAY` | the day is out of the range.
`LUNAR_DATE_ERROR_YEAR` | the year is out of the range.
`LUNAR_DATE_ERROR_LEAP` | the `isleap` parameter of `lunar_date_set_lunar_date()` is not corret.

### lunar_date_error_quark ()

    GQuark              lunar_date_error_quark              (void);

Returns : |

### 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

### lunar_date_set_solar_date ()

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

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

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

### lunar_date_set_lunar_date ()

    void                lunar_date_set_lunar_date           (LunarDate *date,
                                                             GDateYear year,
                                                             GDateMonth month,
                                                             GDateDay day,
                                                             GDateHour 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.

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

### lunar_date_get_jieri ()

    gchar*              lunar_date_get_jieri                (LunarDate *date);

Returns the holiday of the date. The date must be valid.

`date` : | a LunarDate
Returns : | a newly-allocated holiday string of the date. This can be changed in $(datadir)/liblunar/holiday.dat file.

### lunar_date_strftime ()

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

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

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

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

%(NIAN)年%(YUE)月%(RI)日%(SHI)时 阴历：大写->丁亥年腊月十四日

%(nian)年%(yue)月%(ri)日%(shi)时 阴历：小写->2007年12月14日

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

%(y60)年%(m60)月%(d60)日%(h60)时 干支：小写 not use

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

%(y8)年%(m8)月%(d8)日%(h8)时 八字：小写 not use

%(shengxiao) 生肖：猪 %(jieri) 节日(节日、纪念日、节气等)：立春

使用%(jieri)时，如果此日没有节日或节气，那么将为空。 节日可以自定义，只要按照格式修改$(prefix)/share/liblunar/hodiday.dat即可。

`date` : | a LunarDate
`format` : | specify the output format. this
Returns : | a newly-allocated output string, nul-terminated

### lunar_date_free ()

    void                lunar_date_free                     (LunarDate *date);

Frees a LunarDate returned from `lunar_date_new()`.

`date` : | a LunarDate