Day of the year – ShiVa Engine

Day of the year

Function/Handler NAME: GetDayOfYear ( nYear, nMonth, nDayOfMonth )
TYPE: Function
Code Created By, Date and Version: Shaderman – Apr-27-2014 – 1.0
Code Description: Get the day of year for a date, where nMonth is 0 based! Based on a formula from http://en.wikipedia.org/wiki/ISO%5Fweek … given_date
Function/Handler INPUTS: nYear, nMonth, nDayOfMonth -> The year, month and day to check (i.e. 2014, 4, 27)
Function/Handler OUTPUTS: number value. The number of the day (i.e. 117 for 4/27/2014).
REQUIREMENTS: The GetLeapYear function from this KnowledgeBase.

--------------------------------------------------------------------------------
function SmanDateTime.GetDayOfYear ( nYear, nMonth, nDayOfMonth )
--------------------------------------------------------------------------------
    --
    -- Based on code from http://en.wikipedia.org/wiki/ISO%5Fweek%5Fdate#Calculating_the_week_number_of_a_given_date
    --
    if ( this.GetLeapYear ( nYear ) ) then
        local daysToAdd = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }
        return daysToAdd[ nMonth +1 ] + nDayOfMonth
    else
        local daysToAdd = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }
        return daysToAdd[ nMonth +1 ] + nDayOfMonth
    end
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------



Need more answers?

  • slackBanner