Пример #1
0
 /// <summary>
 /// Initializes a new instance from the specified <paramref name="timestamp"/>.
 /// </summary>
 /// <param name="timestamp">The timestamp.</param>
 public EssentialsWeek(EssentialsTime timestamp)
 {
     WeekNumber = timestamp.WeekNumber;
     Start      = timestamp.GetStartOfWeek();
     End        = timestamp.GetEndOfWeek();
     Year       = GetYear();
 }
        /// <summary>
        /// Returns a <see cref="EssentialsPeriod"/> representing the week of <paramref name="timestamp"/> and according to <paramref name="timeZone"/>.
        /// </summary>
        /// <param name="timestamp">The timestamp.</param>
        /// <param name="timeZone">The time zone.</param>
        /// <returns>An instance of <see cref="EssentialsPeriod"/>.</returns>
        public static EssentialsPeriod ThisWeek(DateTimeOffset timestamp, TimeZoneInfo timeZone)
        {
            // Time zone may not be null
            if (timeZone == null)
            {
                throw new ArgumentNullException(nameof(timeZone));
            }

            // Wrap the input "timestamp"
            EssentialsTime time = new EssentialsTime(timestamp);

            // Calculate start and end
            EssentialsTime start = time.GetStartOfWeek(timeZone);
            EssentialsTime end   = time.GetEndOfWeek(timeZone);

            // Wrap the result in a new EssentialsPeriod
            return(new EssentialsPeriod(start, end));
        }