Fan.Sys.DateTime.firstWeekday C# (CSharp) Method

firstWeekday() static private method

Get the first weekday of the specified year and month (0-11).
static private firstWeekday ( int year, int mon ) : int
year int
mon int
return int
        internal static int firstWeekday(int year, int mon)
        {
            // get the 1st day of this month as a day of year (0-365)
              int firstDayOfYear = isLeapYear(year) ? dayOfYearForFirstOfMonLeap[mon] : dayOfYearForFirstOfMon[mon];

              // compute the weekday of the 1st of this month (0-6)
              return (firstWeekdayOfYear[year-1900] + firstDayOfYear) % 7;
        }

Usage Example

Example #1
0
        internal static int weekOfYear(int year, int month, int day, Weekday startOfWeek)
        {
            int firstWeekday       = DateTime.firstWeekday(year, 0); // zero based
            int lastDayInFirstWeek = 7 - (firstWeekday - startOfWeek.ord);

            // special case for first week
            if (month == 0 && day <= lastDayInFirstWeek)
            {
                return(1);
            }

            // compute from dayOfYear - lastDayInFirstWeek
            int doy = dayOfYear(year, month, day) + 1;
            int woy = (doy - lastDayInFirstWeek - 1) / 7;

            return(woy + 2); // add first week and make one based
        }
All Usage Examples Of Fan.Sys.DateTime::firstWeekday