BB.Caching.Redis.Analytics.BitwiseAnalytics.GetMonth C# (CSharp) Method

GetMonth() public static method

Gets the key for the month covered by the DateTime supplied, creating the data at the key if necessary.
public static GetMonth ( IDatabase database, string category, string action, System.DateTime dateTime ) : RedisKey
database IDatabase /// The database where the query will be performed. This is passed so that we can reuse the same database to /// perform multiple bitwise operations. Doing this with the same connection will guarantee that performance /// is good. ///
category string /// Typically the object that was interacted with (e.g. button) ///
action string /// The type of interaction (e.g. click) ///
dateTime System.DateTime /// The DateTime. ///
return RedisKey
        public static RedisKey GetMonth(IDatabase database, string category, string action, DateTime dateTime)
        {
            // get the key
            string month = BitwiseAnalytics.DateTimeUtil.OneMonth(dateTime);
            RedisKey key = EventKey(category, action, month);

            // return it if there's already data for this month
            bool monthExists = BitwiseAnalytics.Exists(database, key);
            if (monthExists)
            {
                return month;
            }

            // no data for the month, so we need to create it from the days
            string[] daysInMonth = BitwiseAnalytics.DateTimeUtil.DaysInMonth(dateTime);

            // make sure each day exists
            foreach (string day in daysInMonth)
            {
                GetDay(database, category, action, DateTime.ParseExact(day, "yyyyMMdd", CultureInfo.InvariantCulture));
            }

            // combine the days to form one month
            BitwiseAnalytics.BitwiseOr(
                database,
                key,
                daysInMonth.Select(x => EventKey(category, action, x)).ToArray());

            return key;
        }