/// <summary> /// Rounds the specified UTC date by discarding the extra date/time components per supplied detalization level /// </summary> public static DateTime RoundDatePerDetalization(DateTime utcDate, VolumeDetalizationLevel level) { switch (level) { case VolumeDetalizationLevel.Quarter: var mi = utcDate.Month - 1; mi -= (mi % 3); var month = mi + 1; return(new DateTime(utcDate.Year, month, day: 1, hour: 12, minute: 0, second: 0, kind: DateTimeKind.Utc)); case VolumeDetalizationLevel.Monthly: return(new DateTime(utcDate.Year, utcDate.Month, day: 1, hour: 12, minute: 0, second: 0, kind: DateTimeKind.Utc)); case VolumeDetalizationLevel.Weekly: var dt = DayOfWeek.Sunday - utcDate.DayOfWeek; DateTime result = utcDate.AddDays(dt); return(new DateTime(result.Year, result.Month, result.Day, hour: 12, minute: 0, second: 0, kind: DateTimeKind.Utc)); case VolumeDetalizationLevel.Daily: return(new DateTime(utcDate.Year, utcDate.Month, utcDate.Day, hour: 12, minute: 0, second: 0, kind: DateTimeKind.Utc)); case VolumeDetalizationLevel.Hourly: return(new DateTime(utcDate.Year, utcDate.Month, utcDate.Day, utcDate.Hour, minute: 0, second: 0, kind: DateTimeKind.Utc)); case VolumeDetalizationLevel.Fractional: var minute = utcDate.Minute; minute -= (minute % FRACTIONAL_FREQUENCY_MINUTES); return(new DateTime(utcDate.Year, utcDate.Month, utcDate.Day, utcDate.Hour, minute: minute, second: 0, kind: DateTimeKind.Utc)); default: throw new SocialException(StringConsts.TS_VOLUME_UNKNOWN_DETALIZATION_ERROR.Args(level)); } }
/// <summary> /// Maps the detalization level to minutes /// </summary> public static int MapDetalizationToMinutes(VolumeDetalizationLevel level) { switch (level) { case VolumeDetalizationLevel.Quarter: return(24 * 60 * 30 * 3); case VolumeDetalizationLevel.Monthly: return(24 * 60 * 30); case VolumeDetalizationLevel.Weekly: return(24 * 60 * 7); case VolumeDetalizationLevel.Daily: return(24 * 60); case VolumeDetalizationLevel.Hourly: return(60); case VolumeDetalizationLevel.Fractional: return(5); default: throw new SocialException(StringConsts.TS_VOLUME_UNKNOWN_DETALIZATION_ERROR.Args(level)); } }