float calendar::sunlight() const { const time_duration now = time_past_midnight( *this ); const time_duration sunrise = time_past_midnight( this->sunrise() ); const time_duration sunset = time_past_midnight( this->sunset() ); const double daylight_level = current_daylight_level(); int current_phase = static_cast<int>( get_moon_phase( *this ) ); if( current_phase > static_cast<int>( MOON_PHASE_MAX ) / 2 ) { current_phase = static_cast<int>( MOON_PHASE_MAX ) - current_phase; } const int moonlight = 1 + static_cast<int>( current_phase * MOONLIGHT_PER_QUARTER ); if( now > sunset + twilight_duration || now < sunrise ) { // Night return moonlight; } else if( now >= sunrise && now <= sunrise + twilight_duration ) { const double percent = ( now - sunrise ) / twilight_duration; return static_cast<double>( moonlight ) * ( 1. - percent ) + daylight_level * percent; } else if( now >= sunset && now <= sunset + twilight_duration ) { const double percent = ( now - sunset ) / twilight_duration; return daylight_level * ( 1. - percent ) + static_cast<double>( moonlight ) * percent; } else { return daylight_level; } }
void update_display_moon(PblTm *tick_time) { // Moon int year_number = 2012; int month_number = 01; int day_number = 01; year_number = tick_time->tm_year + 1900; month_number = tick_time->tm_mon; day_number = tick_time->tm_mday; char *temp = itoa(get_moon_phase(year_number, month_number, day_number)); text_layer_set_text(&moon, temp); }