Example #1
0
void Solar2Lunar(struct LibLunarContext *ctx,
                 SSLunarSimpleDate *solar)
{
    
    long offset;
    
    if (ctx == NULL) {
        fprintf(stderr, "Soloar2Lunar: ctx pointer cannot be NULL");
        return;
    }

    if (!libLunarCheckYearRange(solar->year)) {
            fprintf(stderr, "Solar2Lunar: the year provide exceeds lib's ablility.");
            return;
    }
            
    
    offset = Solar2Day(solar);
    solar->weekday = (offset + SolarFirstDate.weekday) % 7;
    
    /* A lunar day begins at 11 p.m. */
    if (solar->hour == 23)
        offset++;
    
    Day2Lunar(ctx, offset);
    ctx->_lunar.hour = solar->hour;
    CalGZ(offset, &ctx->_lunar, &ctx->_gan, &ctx->_zhi);
    
    jieAlert = JieDate(solar, &ctx->_lunar2);
    ctx->_lunar2.day = ctx->_lunar.day;
    ctx->_lunar2.hour = ctx->_lunar.hour;
    CalGZ(offset, &ctx->_lunar2, &ctx->_gan2, &ctx->_zhi2);
}
Example #2
0
void Solar2Lunar()
{

    long offset;
    Date *d;

    offset = Solar2Day(&solar);
    solar.weekday = (offset + SolarFirstDate.weekday) % 7;

    /* A lunar day begins at 11 p.m. */
    if (solar.hour == 23)
        offset++;

    Day2Lunar(offset, &lunar);
    lunar.hour = solar.hour;
    CalGZ(offset, &lunar, &gan, &zhi);

    jieAlert = JieDate(&solar, &lunar2);
    lunar2.day = lunar.day;
    lunar2.hour = lunar.hour;
    CalGZ(offset, &lunar2, &gan2, &zhi2);
}
Example #3
0
void Day2Solar(LibLunarContext *ctx,
               long offset)
{
    int	i, m, days;
    SSLunarSimpleDate *d = &ctx->_solar;
    
    /* offset is the number of days from SolarFirstDate */
    offset -= Solar2Day(&LunarFirstDate);  /* the argument is negative */
    /* offset is now the number of days from SolarFirstDate.year.1.1 */
    
    for (i=SolarFirstDate.year;
         (i<SolarFirstDate.year+Nyear) && (offset > 0);	 i++)
        offset -= 365 + LeapYear(i);
    if (offset<0)
    {
        --i; 	/* LeapYear is a macro */
        offset += 365 + LeapYear(i);
    }
    if (i==(SolarFirstDate.year + Nyear)) Error("Year out of range.");
    d->year = i;
    
    /* assert(offset<(365+LeapYear(i))); */
    for (m=1; m<=12; m++)
    {
        days = daysInSolarMonth[m];
        if ((m==2) && LeapYear(i))	/* leap February */
            days++;
        if (offset<days)
        {
            d->month = m;
            d->day = offset + 1;
            return;
        }
        offset -= days;
    }
}