Table of Contents

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

timeSpan TimeSpan
calculateTime bool
lang LangsDt

Returns

string

AppendToFrontOnlyTime(string)

Return actual time(for example 12:00:00:000) and after that A1 postfix

public static string AppendToFrontOnlyTime(string defin)

Parameters

defin string

Returns

string

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

dateTime DateTime

The birth/start date

calculateTime bool

Whether to include time units (hours, minutes, seconds)

dtMinVal DateTime

The 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

dateTime DateTime

The birth/start date

calculateTime bool

Whether to include time units (hours, minutes, seconds)

lang LangsDt

The language for localization

dtMinVal DateTime

The 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

AddedAgo string

The 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

dateTime DateTime

Returns

string

DateAndTimeToStringFormalizeDate(DateTime)

1989-06-21T11:22:00

public static string DateAndTimeToStringFormalizeDate(DateTime dateTime)

Parameters

dateTime DateTime

Returns

string

DateTimeToFileName(DateTime)

yyyy_mm_dd

public static string DateTimeToFileName(DateTime dateTime)

Parameters

dateTime DateTime

Returns

string

DateTimeToFileName(DateTime, bool)

yyyy_mm_dd With A2 append hh_mm

public static string DateTimeToFileName(DateTime dateTime, bool time)

Parameters

dateTime DateTime
time bool

Returns

string

DateTimeToSecondsOnlyTime(DateTime)

Converts a DateTime's time component to total seconds as a non-normalized long value.

public static long DateTimeToSecondsOnlyTime(DateTime dateTime)

Parameters

dateTime DateTime

The 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

dateTime DateTime

The DateTime to format

lang LangsDt

The language determining the format

dtMinVal DateTime

The 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

dateTime DateTime

Returns

string

DateTimeToStringFormalizeDateEmptyTime(DateTime)

yyyy-mm-ddT00:00:00

public static string DateTimeToStringFormalizeDateEmptyTime(DateTime dateTime)

Parameters

dateTime DateTime

Returns

string

DateTimeToStringStringifyDateEmptyTime(DateTime)

1989-06-21T00:00:00.000Z

public static string DateTimeToStringStringifyDateEmptyTime(DateTime dateTime)

Parameters

dateTime DateTime

Returns

string

DateTimeToStringStringifyDateTime(DateTime)

1989-06-21Thh:mm:ss.000Z

public static string DateTimeToStringStringifyDateTime(DateTime dateTime)

Parameters

dateTime DateTime

Returns

string

DateTimeToStringToInputDateTimeLocal(DateTime, DateTime)

1989-06-21T11:22

public static string DateTimeToStringToInputDateTimeLocal(DateTime dateTime, DateTime dtMinVal)

Parameters

dateTime DateTime
dtMinVal DateTime

Returns

string

DateTimeToStringWithDayOfWeekCS(DateTime)

Wednesday, 21.6.1989 11:22 (dont fill with zero)

public static string DateTimeToStringWithDayOfWeekCS(DateTime dateTime)

Parameters

dateTime DateTime

Returns

string

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

parameter DateTime

The DateTime to format

lang LangsDt

The language determining the format

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

dateTime DateTime

The 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

parameter DateTime

The DateTime to format

lang LangsDt

The language determining the format

dtMinVal DateTime

The minimum DateTime value representing an unset date

Returns

string

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

dateTime DateTime

The 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

dateTime DateTime

Returns

string

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

dateTime DateTime

The DateTime to format

lang LangsDt

The language determining the format and day name

Returns

string

DayOfWeek2DenVTydnu(DayOfWeek)

Converts a DayOfWeek enum value to its Czech name (e.g. Monday becomes "Pondělí").

public static string DayOfWeek2DenVTydnu(DayOfWeek dayOfWeek)

Parameters

dayOfWeek DayOfWeek

The 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

filenameWithoutExtension string

Returns

DateTime?

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

filenameWithoutExtension string
time bool
postfix string

Returns

DateTime?

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

filenameWithoutExtension string
time bool
prefix string

Returns

DateTime?

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

filenameWithoutExtension string
serie int?
postfix string

Returns

DateTime?

FormatDateTime(DateTime, DateTimeFormatStyles)

2011-10-18 10:30

public static string FormatDateTime(DateTime dateTime, DateTimeFormatStyles fullCalendar)

Parameters

dateTime DateTime
fullCalendar DateTimeFormatStyles

Returns

string

IsValidDateText(string)

Validates whether the text represents a valid date. Returns DateTime.MinValue if invalid.

public static DateTime IsValidDateText(string text)

Parameters

text string

The 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

text string

The 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

text string

The 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

text int

The 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

parameter DateTime

The 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

duration TimeSpan

The duration of the operation

lang LangsDt

The language for localization

Returns

string

Localized duration string

ParseDateCzech(string)

21.6.1989

public static DateTime ParseDateCzech(string text)

Parameters

text string

Returns

DateTime

ParseDateMonthDayYear(string)

Parses a date in month/day/year format (e.g. mm/d/yyyy).

public static DateTime? ParseDateMonthDayYear(string text)

Parameters

text string

The date text to parse

Returns

DateTime?

ParseDateUSA(string)

Parses a date string in US format (mm/dd/yyyy).

public static DateTime ParseDateUSA(string text)

Parameters

text string

The 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

text string

The text containing month shortcut and day

ConvertMonthShortcutNumberFromShortcut Func<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

text string

Returns

DateTime

ParseTimeUSA(string)

Seconds can be omit hh:mm tt

public static DateTime ParseTimeUSA(string text)

Parameters

text string

Returns

DateTime

StringToDateTimeFormalizeDate(string)

Parses a formalized date string (e.g. 2018-08-10T11:33:19Z) into DateTime.

public static DateTime StringToDateTimeFormalizeDate(string text)

Parameters

text string

The formalized date string to parse

Returns

DateTime

StringToDateTimeFromInputDateTimeLocal(string, DateTime)

Input in format like 2015-09-03T21:01

public static DateTime StringToDateTimeFromInputDateTimeLocal(string text, DateTime dtMinVal)

Parameters

text string

Input text in format YYYY-MM-DDTHH:MM

dtMinVal DateTime

Minimum DateTime value

Returns

DateTime

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

parameter Stopwatch

The 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

dateTime DateTime

The 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