Пример #1
0
 /// <summary>
 /// Initializes a new instance based on the specified <paramref name="year"/>, <paramref name="week"/> and <paramref name="offset"/>.
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="week">The week number.</param>
 /// <param name="offset">The offset.</param>
 public EssentialsWeek(int year, int week, TimeSpan offset)
 {
     WeekNumber = week;
     Year       = year;
     Start      = Iso8601Utils.FromWeekNumber(year, week, offset);
     End        = Start.GetEndOfWeek();
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance from the specified <paramref name="timestamp"/>.
 /// </summary>
 /// <param name="timestamp">The timestamp.</param>
 public EssentialsWeek(DateTimeOffset timestamp)
 {
     Week  = TimeUtils.GetIso8601WeekNumber(timestamp);
     Start = TimeUtils.GetStartOfWeek(timestamp);
     End   = TimeUtils.GetEndOfWeek(timestamp);
     Year  = GetYear();
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance based on the specified <paramref name="year"/>, <paramref name="week"/> and <paramref name="offset"/>.
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="week">The week number.</param>
 /// <param name="offset">The offset.</param>
 public EssentialsWeek(int year, int week, TimeSpan offset)
 {
     Week  = week;
     Year  = year;
     Start = TimeUtils.GetDateTimeOffsetFromIso8601Week(year, week, offset);
     End   = Start.GetEndOfWeek();
 }
Пример #4
0
 /// <summary>
 /// Initializes a new month based on the specified <paramref name="year"/> and <paramref name="month"/>.
 ///
 /// Timestamps for start and end will be calculated using <paramref name="timeZone"/>.
 /// </summary>
 /// <param name="year"></param>
 /// <param name="month"></param>
 /// <param name="timeZone"></param>
 public EssentialsMonth(int year, int month, TimeZoneInfo timeZone)
 {
     Year  = year;
     Month = month;
     Start = new EssentialsTime(year, month, 1, timeZone);
     End   = Start.GetEndOfMonth(timeZone);
 }
Пример #5
0
 /// <summary>
 /// Returns an enumerator that iterates through the days of the week.
 /// </summary>
 /// <returns>An enumerator that can be used to iterate through the days of the week.</returns>
 public IEnumerator <EssentialsDate> GetEnumerator()
 {
     for (EssentialsTime day = Start; day < End; day = day.AddDays(1))
     {
         yield return(new EssentialsDate(day));
     }
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance from the specified <paramref name="date"/> and <paramref name="timeZone"/>.
 /// </summary>
 /// <param name="date">The dare.</param>
 /// <param name="timeZone">The time zone.</param>
 public EssentialsWeek(EssentialsDate date, TimeZoneInfo timeZone)
 {
     WeekNumber = date.WeekNumber;
     Start      = date.GetStartOfWeek(timeZone);
     End        = date.GetEndOfWeek(timeZone);
     Year       = GetYear();
 }
Пример #7
0
 /// <summary>
 /// Initializes a new instance from the specified <paramref name="timestamp"/>.
 /// </summary>
 /// <param name="timestamp">The timestamp.</param>
 public EssentialsWeek(EssentialsTime timestamp)
 {
     Week  = TimeUtils.GetIso8601WeekNumber(timestamp.DateTimeOffset);
     Start = TimeUtils.GetStartOfWeek(timestamp.DateTimeOffset, timestamp.TimeZone);
     End   = TimeUtils.GetEndOfWeek(timestamp.DateTimeOffset, timestamp.TimeZone);
     Year  = GetYear();
 }
Пример #8
0
 /// <summary>
 /// Initializes a new instance based on the specified <paramref name="year"/>, <paramref name="week"/> and <paramref name="timeZone"/>.
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="week">The week number.</param>
 /// <param name="timeZone">The time zone.</param>
 public EssentialsWeek(int year, int week, TimeZoneInfo timeZone)
 {
     Week  = week;
     Year  = year;
     Start = EssentialsTime.FromIso8601Week(year, week, timeZone);
     End   = Start.GetEndOfWeek(timeZone);
 }
Пример #9
0
 /// <summary>
 /// Initializes a new instance from the specified <paramref name="date"/>.
 /// </summary>
 /// <param name="date">The dare.</param>
 public EssentialsWeek(EssentialsDate date)
 {
     WeekNumber = date.WeekNumber;
     Start      = date.GetStartOfWeek();
     End        = date.GetEndOfWeek();
     Year       = GetYear();
 }
Пример #10
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();
 }
Пример #11
0
 /// <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();
 }
Пример #12
0
 /// <summary>
 /// Initializes a new instance from the specified <paramref name="date"/>.
 /// </summary>
 /// <param name="date">An instance of <see cref="EssentialsTime"/> representing the full date.</param>
 public EssentialsPartialDate(EssentialsTime date)
 {
     Year     = date == null ? 0 : date.Year;
     Month    = date == null ? 0 : date.Month;
     Day      = date == null ? 0 : date.Day;
     DateTime = new DateTime(Year == 0 ? 1 : Year, Month == 0 ? 1 : Month, Day == 0 ? 1 : Day);
 }
Пример #13
0
        /// <summary>
        /// Initializes a new instance for the year containing the specified <paramref name="timestamp"/>.
        ///
        /// If <paramref name="timestamp"/> doesn't specify a timestamp (eg. only an offset), the timestamp will be converted to <see cref="TimeZoneInfo.Local"/>.
        /// </summary>
        /// <param name="timestamp">A timestamp representing the year to be created.</param>
        public EssentialsYear(EssentialsTime timestamp)
        {
            if (timestamp == null)
            {
                throw new ArgumentNullException(nameof(timestamp));
            }

            if (timestamp.TimeZone == null)
            {
                timestamp = timestamp.ToTimeZone(TimeZoneInfo.Local);
            }

            Year  = timestamp.Year;
            Start = new EssentialsTime(timestamp.Year, 1, 1, timestamp.TimeZone);
            End   = new EssentialsTime(timestamp.Year, 12, 31, timestamp.TimeZone).GetEndOfDay();
        }
Пример #14
0
        /// <summary>
        /// Initializes a new instance for the month containing the specified <paramref name="timestamp"/>.
        ///
        /// If <paramref name="timestamp"/> doesn't specify a timestamp (eg. only an offset), the timestamp will be converted to <see cref="TimeZoneInfo.Local"/>.
        /// </summary>
        /// <param name="timestamp">A timestamp representing the month to be created.</param>
        public EssentialsMonth(EssentialsTime timestamp)
        {
            if (timestamp == null)
            {
                throw new ArgumentNullException(nameof(timestamp));
            }

            if (timestamp.TimeZone == null)
            {
                timestamp = timestamp.ToTimeZone(TimeZoneInfo.Local);
            }

            Year  = timestamp.Year;
            Month = timestamp.Month;
            Start = timestamp.GetStartOfMonth();
            End   = timestamp.GetEndOfMonth();
        }
Пример #15
0
        /// <summary>
        /// Returns a <see cref="EssentialsPeriod"/> representing the month of <paramref name="dto"/> and according to <paramref name="timeZone"/>.
        /// </summary>
        /// <param name="dto">The timestamp.</param>
        /// <param name="timeZone">The time zone.</param>
        /// <returns>An instance of <see cref="EssentialsPeriod"/>.</returns>
        public static EssentialsPeriod ThisMonth(DateTimeOffset dto, TimeZoneInfo timeZone)
        {
            // Time zone may not be null
            if (timeZone == null)
            {
                throw new ArgumentNullException(nameof(timeZone));
            }

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

            // Calculate start and end
            EssentialsTime start = time.GetStartOfMonth(timeZone);
            EssentialsTime end   = time.GetEndOfMonth(timeZone);

            // Wrap the result in a new EssentialsPeriod
            return(new EssentialsPeriod(start, end));
        }
Пример #16
0
 /// <summary>
 /// Initializes a new instance based on the specified <paramref name="start"/> and <paramref name="end"/>
 /// dates. Both dates will be adjusted according to the specified <paramref name="timeZone"/>.
 /// </summary>
 /// <param name="start">The start date.</param>
 /// <param name="end">The end date.</param>
 /// <param name="timeZone">The time zone.</param>
 public EssentialsPeriod(DateTimeOffset start, DateTimeOffset end, TimeZoneInfo timeZone)
 {
     Start = new EssentialsTime(start, timeZone ?? TimeZoneInfo.Local);
     End   = new EssentialsTime(end, timeZone ?? TimeZoneInfo.Local);
 }
Пример #17
0
 /// <summary>
 /// Initializes a new instance based on the specified <paramref name="start"/> and <paramref name="end"/> dates.
 /// </summary>
 /// <param name="start">The start date.</param>
 /// <param name="end">The end date.</param>
 public EssentialsPeriod(EssentialsTime start, EssentialsTime end)
 {
     Start = start;
     End   = end;
 }
Пример #18
0
 /// <summary>
 /// Compares the value of this instance to a specified <see cref="EssentialsTime"/> value and returns an
 /// integer that indicates whether this instance is lower than, the same as, or greater than the specified
 /// <see cref="EssentialsTime"/> value.
 /// </summary>
 /// <param name="value">The value to compare to the current instance.</param>
 /// <returns>A signed number indicating the relative values of this instance and the <paramref name="value"/>
 /// parameter.</returns>
 public int CompareTo(EssentialsTime value)
 {
     return(value == null ? 1 : string.Compare(Iso8601, value.ToString("yyyy-MM-dd"), StringComparison.CurrentCultureIgnoreCase));
 }
Пример #19
0
 private static int CompareTo(EssentialsDate d1, EssentialsTime d2)
 {
     return(string.Compare(d1?.Iso8601, d2?.ToString("yyyy-MM-dd"), StringComparison.CurrentCultureIgnoreCase));
 }
Пример #20
0
 /// <summary>
 /// Initializes a new year based on the specified <paramref name="year"/>.
 ///
 /// Timestamps for start and end will be calculated using <paramref name="timeZone"/>.
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="timeZone">The time zone used for calculating the start and end of the year.</param>
 public EssentialsYear(int year, TimeZoneInfo timeZone)
 {
     Year  = year;
     Start = new EssentialsTime(year, 1, 1, timeZone);
     End   = new EssentialsTime(year, 12, 31, timeZone).GetEndOfDay();
 }
Пример #21
0
 /// <summary>
 /// Initializes a new instance from the specified <paramref name="time"/>.
 /// </summary>
 /// <param name="time">An instance of <see cref="EssentialsTime"/>.</param>
 public EssentialsDate(EssentialsTime time)
 {
     _dateTime = time.DateTimeOffset.DateTime;
 }