Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applied the null-condition operator to format dates #173

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/Extensions/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
public static class DateTimeExtensions
{
public static string GetDateInSpanishFormat(this DateTime dateTime)
=> dateTime.ToString("D", new System.Globalization.CultureInfo("es-ES"));
=> dateTime.ToString("D", new CultureInfo("es-ES"));

public static string GetDateAndHourInSpanishFormat(this DateTime dateTime)
=> dateTime.ToString("f", new System.Globalization.CultureInfo("es-ES"));
=> dateTime.ToString("f", new CultureInfo("es-ES"));

public static string GetDateWithStandardFormat(this DateTime dateTime)
=> dateTime.ToString("yyyy-MM-dd");

public static string GetDateAndHourInSpanishFormat(this DateTime? dateTimeNullable)
{
if (dateTimeNullable is null)
return null;
DateTime dt = (DateTime)dateTimeNullable;
return dt.ToString("f", new System.Globalization.CultureInfo("es-ES"));
}
public static string GetDateAndHourInSpanishFormat(this DateTime? dateTime)
=> dateTime?.ToString("f", new CultureInfo("es-ES"));
}
1 change: 1 addition & 0 deletions src/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
global using static DentallApp.Constants.ResponseMessages;
global using static DentallApp.Constants.MessageTemplates;

global using System.Globalization;
global using System.Data;
global using System.Text;
global using System.Net.Mime;
Expand Down