/// <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(); }
/// <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(); }
/// <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(); }
/// <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); }
/// <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)); } }
/// <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(); }
/// <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(); }
/// <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); }
/// <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(); }
/// <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> /// 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> /// 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); }
/// <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(); }
/// <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(); }
/// <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)); }
/// <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); }
/// <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; }
/// <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)); }
private static int CompareTo(EssentialsDate d1, EssentialsTime d2) { return(string.Compare(d1?.Iso8601, d2?.ToString("yyyy-MM-dd"), StringComparison.CurrentCultureIgnoreCase)); }
/// <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(); }
/// <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; }