Exemplo n.º 1
0
 /// <summary>
 /// Converts the specified <paramref name="monthName"/> into an enum representation of the month
 /// (eg. <c>August</c> is the eight month of the year, and will result in
 /// <see cref="EssentialsDateMonthName.August"/>) and returns a value that indicates whether the conversion
 /// succeeded.
 /// </summary>
 /// <param name="monthName">The name of the month.</param>
 /// <param name="result">When this method returns, contains the <see cref="EssentialsDateMonthName"/> value
 /// equivalent to the month name contained in <paramref name="monthName"/>, if the conversion succeeded, or the
 /// default value of <see cref="EssentialsDateMonthName"/> if the conversion failed. The conversion fails if
 /// <paramref name="monthName"/> is <c>null</c>, is an empty string (""), or does not contain a valid
 /// month name. This parameter is passed uninitialized.</param>
 /// <returns><c>true</c> if <paramref name="monthName"/> was converted successfully; otherwise,
 /// <c>false</c>.</returns>
 public static bool TryParseEnumFromMonthName(string monthName, out EssentialsDateMonthName result)
 {
     return(TryParseEnumFromMonthName(monthName, CultureInfo.InvariantCulture, out result));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Converts the specified <paramref name="monthName"/> into an enum representation of the month
 /// (eg. <c>August</c> is the eight month of the year, and will result in
 /// <see cref="EssentialsDateMonthName.August"/>) and returns a value that indicates whether the conversion
 /// succeeded.
 /// </summary>
 /// <param name="monthName">The name of the month.</param>
 /// <param name="result">When this method returns, contains the <see cref="EssentialsDateMonthName"/> value
 /// equivalent to the month name contained in <paramref name="monthName"/>, if the conversion succeeded, or the
 /// default value of <see cref="EssentialsDateMonthName"/> if the conversion failed. The conversion fails if
 /// <paramref name="monthName"/> is <c>null</c>, is an empty string (""), or does not contain a valid
 /// month name. This parameter is passed uninitialized.</param>
 /// <param name="provider">An object that supplies culture-specific format information about
 /// <paramref name="monthName"/>.</param> <returns><c>true</c> if <paramref name="monthName"/> was converted
 /// successfully; otherwise, <c>false</c>.</returns>
 public static bool TryParseEnumFromMonthName(string monthName, IFormatProvider provider, out EssentialsDateMonthName result)
 {
     if (string.IsNullOrWhiteSpace(monthName))
     {
         throw new ArgumentNullException(nameof(monthName));
     }
     result = 0;
     if (!DateTime.TryParseExact(monthName, "MMMM", provider, DateTimeStyles.None, out DateTime dt))
     {
         return(false);
     }
     result = (EssentialsDateMonthName)dt.Month;
     return(true);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the last day of the month that matches <paramref name="dayOfWeek"/>..
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="month">The month.</param>
 /// <param name="dayOfWeek">The weekday to match.</param>
 /// <param name="offset">The time's offset from Coordinated Universal Time (UTC).</param>
 /// <returns>An instance of <see cref="DateTimeOffset"/> representing the day.</returns>
 public static DateTimeOffset GetLastWeekdayOfMonth(int year, EssentialsDateMonthName month, DayOfWeek dayOfWeek, TimeSpan offset)
 {
     return(GetLastWeekdayOfMonth(year, (int)month, dayOfWeek, offset));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Gets the first day of the month that matches <paramref name="dayOfWeek"/>..
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="month">The month.</param>
 /// <param name="dayOfWeek">The weekday to match.</param>
 /// <returns>An instance of <see cref="DateTime"/> representing the day.</returns>
 public static DateTime GetFirstWeekdayOfMonth(int year, EssentialsDateMonthName month, DayOfWeek dayOfWeek)
 {
     return(GetFirstWeekdayOfMonth(year, (int)month, dayOfWeek));
 }
Exemplo n.º 5
0
 private static DateTime GetDate(int year, EssentialsDateMonthName month, int day)
 {
     return(new DateTime(year, (int)month, day));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Gets the last day of the month that matches <paramref name="dayOfWeek"/>.
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="month">The month.</param>
 /// <param name="dayOfWeek">The weekday to match.</param>
 /// <returns>An instance of <see cref="DateTimeOffset"/> representing the day.</returns>
 public static DateTimeOffset GetLastWeekdayOfMonth(int year, EssentialsDateMonthName month, DayOfWeek dayOfWeek)
 {
     return(TimeUtils.GetLastWeekdayOfMonth(year, month, dayOfWeek));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the first day of the month that matches <paramref name="dayOfWeek"/>.
 /// </summary>
 /// <param name="year">The year.</param>
 /// <param name="month">The month.</param>
 /// <param name="dayOfWeek">The weekday to match.</param>
 /// <returns>An instance of <see cref="DateTimeOffset"/> representing the day.</returns>
 /// <param name="offset">The time's offset from Coordinated Universal Time (UTC).</param>
 public static DateTimeOffset GetFirstWeekdayOfMonth(int year, EssentialsDateMonthName month, DayOfWeek dayOfWeek, TimeSpan offset)
 {
     return(TimeUtils.GetFirstWeekdayOfMonth(year, month, dayOfWeek, offset));
 }