/// <summary> /// Initializes a new instance from the specified <paramref name="timestamp"/> and <paramref name="timeZone"/>. /// </summary> /// <param name="timestamp">The timestamp.</param> /// <param name="timeZone">The time zone.</param> public EssentialsWeek(DateTimeOffset timestamp, TimeZoneInfo timeZone) { WeekNumber = Iso8601Utils.GetWeekNumber(timestamp); Start = TimeUtils.GetStartOfWeek(timestamp, timeZone); End = TimeUtils.GetEndOfWeek(timestamp, timeZone); Year = GetYear(); }
/// <summary> /// Initialize a new instance based on the specified <paramref name="timestamp"/>. /// </summary> /// <param name="timestamp">A timestamp.</param> public EssentialsDateWeek(EssentialsDateTime timestamp) { Week = Iso8601Utils.GetWeekNumber(timestamp.DateTime); Start = TimeUtils.GetFirstDayOfWeek(timestamp.DateTime); End = TimeUtils.GetLastDayOfWeek(timestamp.DateTime); if (End.Month == 1 && Week == 1) { Year = End.Year; } else if (Start.Month == 12 && Week >= 50) { Year = Start.Year; } else { Year = timestamp.Year; } }
/// <summary> /// Gets the week number of the specified <paramref name="date"/> according to the <strong>ISO 8601</strong> /// specification. /// </summary> /// <param name="date">An instance of <see cref="DateTimeOffset"/> representing the date.</param> /// <returns>An instance of <see cref="int"/> representing the <strong>ISO 8601</strong> week number.</returns> public static int GetIso8601WeekNumber(this DateTimeOffset date) { return(Iso8601Utils.GetWeekNumber(date)); }