Class DTHelper
- Namespace
- SunamoDateTime.DT
- Assembly
- SunamoDateTime.dll
Main facade class providing DateTime parsing, formatting and validation operations. Delegates to specialized helper classes.
public class DTHelper
- Inheritance
-
DTHelper
- Inherited Members
- Extension Methods
Methods
AddRightStringToTimeSpan(TimeSpan, bool, LangsDt)
If A1 could be lower than 1d, return 1d
public static string AddRightStringToTimeSpan(TimeSpan timeSpan, bool calculateTime, LangsDt lang)
Parameters
Returns
AppendToFrontOnlyTime(string)
Return actual time(for example 12:00:00:000) and after that A1 postfix
public static string AppendToFrontOnlyTime(string defin)
Parameters
definstring
Returns
CalculateAgeAndAddRightString(DateTime, bool, DateTime)
Calculates age from a date and returns it as a Czech localized string with nominative case.
public static string CalculateAgeAndAddRightString(DateTime dateTime, bool calculateTime, DateTime dtMinVal)
Parameters
dateTimeDateTimeThe birth/start date
calculateTimeboolWhether to include time units (hours, minutes, seconds)
dtMinValDateTimeThe minimum DateTime value representing an unset date
Returns
- string
Localized age string
CalculateAgeAndAddRightStringKymCim(DateTime, bool, LangsDt, DateTime)
Calculates the age from a date and returns it as a Czech localized string with instrumental case (kym/cim).
public static string CalculateAgeAndAddRightStringKymCim(DateTime dateTime, bool calculateTime, LangsDt lang, DateTime dtMinVal)
Parameters
dateTimeDateTimeThe birth/start date
calculateTimeboolWhether to include time units (hours, minutes, seconds)
langLangsDtThe language for localization
dtMinValDateTimeThe minimum DateTime value representing an unset date
Returns
- string
Localized age string in instrumental case
CalculateStartOfPeriod(string)
Calculates a past date by subtracting the specified period (e.g. "7_days", "2_weeks") from today.
public static DateTime CalculateStartOfPeriod(string AddedAgo)
Parameters
AddedAgostringThe period string in format "number_unit" (days/weeks/months/years)
Returns
- DateTime
The calculated past DateTime
DateAndTimeToStringAngularDateTime(DateTime)
19890621T11:22:00
public static string DateAndTimeToStringAngularDateTime(DateTime dateTime)
Parameters
dateTimeDateTime
Returns
DateAndTimeToStringFormalizeDate(DateTime)
1989-06-21T11:22:00
public static string DateAndTimeToStringFormalizeDate(DateTime dateTime)
Parameters
dateTimeDateTime
Returns
DateTimeToFileName(DateTime)
yyyy_mm_dd
public static string DateTimeToFileName(DateTime dateTime)
Parameters
dateTimeDateTime
Returns
DateTimeToFileName(DateTime, bool)
yyyy_mm_dd With A2 append hh_mm
public static string DateTimeToFileName(DateTime dateTime, bool time)
Parameters
Returns
DateTimeToSecondsOnlyTime(DateTime)
Converts a DateTime's time component to total seconds as a non-normalized long value.
public static long DateTimeToSecondsOnlyTime(DateTime dateTime)
Parameters
dateTimeDateTimeThe DateTime whose time to convert
Returns
- long
Time in seconds as a long value
DateTimeToString(DateTime, LangsDt, DateTime)
Formats a DateTime as a localized date-time string, or returns "not indicated" text if equal to minimum value.
public static string DateTimeToString(DateTime dateTime, LangsDt lang, DateTime dtMinVal)
Parameters
dateTimeDateTimeThe DateTime to format
langLangsDtThe language determining the format
dtMinValDateTimeThe minimum DateTime value representing an unset date
Returns
- string
Localized date-time string
DateTimeToStringFormalizeDate(DateTime)
1989-06-21
public static string DateTimeToStringFormalizeDate(DateTime dateTime)
Parameters
dateTimeDateTime
Returns
DateTimeToStringFormalizeDateEmptyTime(DateTime)
yyyy-mm-ddT00:00:00
public static string DateTimeToStringFormalizeDateEmptyTime(DateTime dateTime)
Parameters
dateTimeDateTime
Returns
DateTimeToStringStringifyDateEmptyTime(DateTime)
1989-06-21T00:00:00.000Z
public static string DateTimeToStringStringifyDateEmptyTime(DateTime dateTime)
Parameters
dateTimeDateTime
Returns
DateTimeToStringStringifyDateTime(DateTime)
1989-06-21Thh:mm:ss.000Z
public static string DateTimeToStringStringifyDateTime(DateTime dateTime)
Parameters
dateTimeDateTime
Returns
DateTimeToStringToInputDateTimeLocal(DateTime, DateTime)
1989-06-21T11:22
public static string DateTimeToStringToInputDateTimeLocal(DateTime dateTime, DateTime dtMinVal)
Parameters
Returns
DateTimeToStringWithDayOfWeekCS(DateTime)
Wednesday, 21.6.1989 11:22 (dont fill with zero)
public static string DateTimeToStringWithDayOfWeekCS(DateTime dateTime)
Parameters
dateTimeDateTime
Returns
DateToString(DateTime, LangsDt)
Formats a DateTime as a localized date string (cs: d.M.yyyy, en: M/d/yyyy).
public static string DateToString(DateTime parameter, LangsDt lang)
Parameters
Returns
- string
Localized date string
DateToStringAngularDate(DateTime)
Formats a DateTime as an Angular-compatible date string (yyyyMMddT00:00:00).
public static string DateToStringAngularDate(DateTime dateTime)
Parameters
dateTimeDateTimeThe DateTime to format
Returns
- string
Date string in Angular format
DateToStringOrSE(DateTime, LangsDt, DateTime)
Formats a DateTime as a localized date string, or returns empty string if equal to minimum value. (e.g. 21.6.1989)
public static string DateToStringOrSE(DateTime parameter, LangsDt lang, DateTime dtMinVal)
Parameters
parameterDateTimeThe DateTime to format
langLangsDtThe language determining the format
dtMinValDateTimeThe minimum DateTime value representing an unset date
Returns
DateToStringWithDayOfWeekCS(DateTime)
Formats a DateTime as a Czech date string with day of week prefix (e.g. "Středa, 21.6.1989").
public static string DateToStringWithDayOfWeekCS(DateTime dateTime)
Parameters
dateTimeDateTimeThe DateTime to format
Returns
- string
Czech-formatted date string with day of week
DateToStringjQueryDatePicker(DateTime)
mm/dd/yyyy
public static string DateToStringjQueryDatePicker(DateTime dateTime)
Parameters
dateTimeDateTime
Returns
DateWithDayOfWeek(DateTime, LangsDt)
Formats a DateTime as a localized date with day of week in parentheses. (e.g. 21.6.1989 (středa) / 6/21/1989 (wednesday))
public static string DateWithDayOfWeek(DateTime dateTime, LangsDt lang)
Parameters
dateTimeDateTimeThe DateTime to format
langLangsDtThe language determining the format and day name
Returns
DayOfWeek2DenVTydnu(DayOfWeek)
Converts a DayOfWeek enum value to its Czech name (e.g. Monday becomes "Pondělí").
public static string DayOfWeek2DenVTydnu(DayOfWeek dayOfWeek)
Parameters
dayOfWeekDayOfWeekThe day of week to convert
Returns
- string
Czech name of the day
FileNameToDateTime(string)
1989_06_21_11_22
public static DateTime? FileNameToDateTime(string filenameWithoutExtension)
Parameters
filenameWithoutExtensionstring
Returns
FileNameToDateTimePostfix(string, bool, out string)
Return null if wont have right format If A2, A1 must have format ???????????? if !A2, A1 must have format ???????? In any case what is after A2 is not important
public static DateTime? FileNameToDateTimePostfix(string filenameWithoutExtension, bool time, out string postfix)
Parameters
Returns
FileNameToDateTimePrefix(string, bool, out string)
1989_06_21_11_22 or 1989_06_21 if !A2
public static DateTime? FileNameToDateTimePrefix(string filenameWithoutExtension, bool time, out string prefix)
Parameters
Returns
FileNameToDateWithSeriePostfix(string, out int?, out string)
Return null if wont have right format If A2, A1 must have format ???????????? if !A2, A1 must have format ???????? In any case what is after A2 is not important
public static DateTime? FileNameToDateWithSeriePostfix(string filenameWithoutExtension, out int? serie, out string postfix)
Parameters
Returns
FormatDateTime(DateTime, DateTimeFormatStyles)
2011-10-18 10:30
public static string FormatDateTime(DateTime dateTime, DateTimeFormatStyles fullCalendar)
Parameters
dateTimeDateTimefullCalendarDateTimeFormatStyles
Returns
IsValidDateText(string)
Validates whether the text represents a valid date. Returns DateTime.MinValue if invalid.
public static DateTime IsValidDateText(string text)
Parameters
textstringThe date text to validate
Returns
- DateTime
Parsed DateTime if valid, DateTime.MinValue otherwise
IsValidDateTimeText(string)
Validates whether the text represents a valid date and time. Returns DateTime.MinValue if invalid.
public static DateTime IsValidDateTimeText(string text)
Parameters
textstringThe date-time text to validate
Returns
- DateTime
Parsed DateTime if valid, DateTime.MinValue otherwise
IsValidTimeText(string)
Validates whether the text represents a valid time. Returns DateTime.MinValue if invalid.
public static DateTime IsValidTimeText(string text)
Parameters
textstringThe time text to validate
Returns
- DateTime
Parsed DateTime if valid, DateTime.MinValue otherwise
MakeUpTo2NumbersToZero(int)
Formats a number to a two-digit zero-padded string (e.g. 5 becomes "05").
public static string MakeUpTo2NumbersToZero(int text)
Parameters
textintThe number to format
Returns
- string
Two-digit zero-padded string
OnlyDateProperties(DateTime)
Returns a new DateTime with only the date component (year, month, day), zeroing the time part.
public static DateTime OnlyDateProperties(DateTime parameter)
Parameters
parameterDateTimeThe DateTime to extract the date from
Returns
- DateTime
A DateTime with only the date component
OperationLastedInLocalizateString(TimeSpan, LangsDt)
Returns a localized string describing how long an operation lasted.
public static string OperationLastedInLocalizateString(TimeSpan duration, LangsDt lang)
Parameters
Returns
- string
Localized duration string
ParseDateCzech(string)
21.6.1989
public static DateTime ParseDateCzech(string text)
Parameters
textstring
Returns
ParseDateMonthDayYear(string)
Parses a date in month/day/year format (e.g. mm/d/yyyy).
public static DateTime? ParseDateMonthDayYear(string text)
Parameters
textstringThe date text to parse
Returns
ParseDateUSA(string)
Parses a date string in US format (mm/dd/yyyy).
public static DateTime ParseDateUSA(string text)
Parameters
textstringThe date text in US format
Returns
- DateTime
Parsed DateTime, or DateTime.MinValue if parsing fails
ParseLl(string, Func<string, int>)
Parses a date from a text containing a month shortcut and day number (e.g. "Jan 15").
public static DateTime ParseLl(string text, Func<string, int> ConvertMonthShortcutNumberFromShortcut)
Parameters
textstringThe text containing month shortcut and day
ConvertMonthShortcutNumberFromShortcutFunc<string, int>Function to convert month shortcut to month number
Returns
- DateTime
Parsed DateTime with current year
ParseTimeCzech(string)
hh:mm:ss If fail, return DT.MinValue Seconds can be omit
public static DateTime ParseTimeCzech(string text)
Parameters
textstring
Returns
ParseTimeUSA(string)
Seconds can be omit hh:mm tt
public static DateTime ParseTimeUSA(string text)
Parameters
textstring
Returns
StringToDateTimeFormalizeDate(string)
Parses a formalized date string (e.g. 2018-08-10T11:33:19Z) into DateTime.
public static DateTime StringToDateTimeFormalizeDate(string text)
Parameters
textstringThe formalized date string to parse
Returns
StringToDateTimeFromInputDateTimeLocal(string, DateTime)
Input in format like 2015-09-03T21:01
public static DateTime StringToDateTimeFromInputDateTimeLocal(string text, DateTime dtMinVal)
Parameters
Returns
TimeInMsToSeconds(Stopwatch)
Converts elapsed milliseconds from a Stopwatch to a seconds string (e.g. "1.23s") and resets the Stopwatch.
public static string TimeInMsToSeconds(Stopwatch parameter)
Parameters
parameterStopwatchThe Stopwatch to read and reset
Returns
- string
Elapsed time in seconds as string
TimeToStringAngularTime(DateTime)
Formats a DateTime's time component as an Angular-compatible time string (HH:mm:ss).
public static string TimeToStringAngularTime(DateTime dateTime)
Parameters
dateTimeDateTimeThe DateTime whose time to format
Returns
- string
Time string in HH:mm:ss format
TodayPlusActualHour()
Returns today's date with the current hour added.
public static DateTime TodayPlusActualHour()
Returns
- DateTime
Today's date at the current hour