Skip to content

Commit

Permalink
Added "To{Type}" methods to the "EssentialsTime" class
Browse files Browse the repository at this point in the history
The new methods allow converting to "EssentialsDate", "EssentialsWeek", "EssentialsMonth" and "EssentialsYear" respectively. The four types already have constructors for create a new instance from an "EssentialsTime" instance. The new method does the same, but may be more useful in some scenarios - eg. when using method chaining.
  • Loading branch information
abjerner committed Jan 23, 2023
1 parent f55300d commit dc512ef
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Skybrud.Essentials/Time/EssentialsTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,38 @@ public EssentialsTime GetEndOfQuarter(TimeZoneInfo? timeZone) {
return new EssentialsTime(TimeUtils.GetEndOfQuarter(DateTimeOffset, timeZone), timeZone);
}

/// <summary>
/// Returns a new <see cref="EssentialsDate"/> instance representing the date of the this timestamp.
/// </summary>
/// <returns>An instance of <see cref="EssentialsDate"/>.</returns>
public EssentialsDate ToDate() {
return new EssentialsDate(Year, Month, Day);
}

/// <summary>
/// Returns a new <see cref="EssentialsWeek"/> instance representing the ISO 8601 week of the this timestamp.
/// </summary>
/// <returns>An instance of <see cref="EssentialsWeek"/>.</returns>
public EssentialsWeek ToWeek() {
return new EssentialsWeek(this);
}

/// <summary>
/// Returns a new <see cref="EssentialsMonth"/> instance representing the month of the this timestamp.
/// </summary>
/// <returns>An instance of <see cref="EssentialsMonth"/>.</returns>
public EssentialsMonth ToMonth() {
return new EssentialsMonth(this);
}

/// <summary>
/// Returns a new <see cref="EssentialsYear"/> instance representing the year of the this timestamp.
/// </summary>
/// <returns>An instance of <see cref="EssentialsYear"/>.</returns>
public EssentialsYear ToYear() {
return new EssentialsYear(this);
}

#endregion

#region Static methods
Expand Down

0 comments on commit dc512ef

Please sign in to comment.