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;
}