Week of year – ShiVa Engine

Week of year

Function/Handler NAME: GetWeekOfYear ( nYear, nMonth, nDayOfMonth )
TYPE: Function
Code Created By, Date and Version: Shaderman – Apr-27-2014 – 1.0
Code Description: Get the week of the year for a date, where nMonth is 0 based!
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 week (i.e. 17 for 4/27/2014).
REQUIREMENTS: The GetDayOfWeek and GetDayOfYear functions from this KnowledgeBase.

--------------------------------------------------------------------------------
function SmanDateTime.GetWeekOfYear ( nYear, nMonth, nDayOfMonth )
--------------------------------------------------------------------------------
    local nOrdinalDay   = this.GetDayOfYear ( nYear, nMonth, nDayOfMonth )
    local nDayOfWeek    = this.GetDayOfWeek ( nYear, nMonth, nDayOfMonth )
    nDayOfWeek          = nDayOfWeek > 0 and nDayOfWeek or 7 -- ShiVa returns 0 for Sunday, we need it to be 7 (1 for Monday to 7 for Sunday)
    return              math.trunc ( ( nOrdinalDay - nDayOfWeek + 10 ) / 7, 0 )
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------



Need more answers?

  • slackBanner