C# Class fCraft.DateTimeUtil

Provides utility functions for working with DateTime and TimeSpan.
Show file Open project: fragmer/fCraft Class Usage Examples

Public Properties

Property Type Description
MaxTimeSpan System.TimeSpan
UnixEpoch System.DateTime

Public Methods

Method Description
ParseMiniTimeSpan ( [ text ) : System.TimeSpan

Parses the given string as a TimeSpan in compact representation. Throws exceptions on failure.

ParseMiniTimespan ( [ text ) : System.TimeSpan

Parses the given string as a TimeSpan in compact representation. Throws exceptions on failure.

ToDateTime ( long timestamp ) : System.DateTime

Creates a DateTime from a UTC Unix Timestamp.

ToDateTime ( this timestamp ) : System.DateTime

Creates a DateTime from a Utc Unix Timestamp.

ToDateTime ( this str, System.DateTime &result ) : bool

Tries to create a DateTime from a string containing a Utc Unix Timestamp. If the string was empty, returns false and does not affect result.

ToDateTimeLegacy ( this str, System.DateTime &result ) : bool
ToSeconds ( this time ) : long
ToSecondsString ( this time, [ sb ) : void

Serializes the given TimeSpan to the given StringBuilder, as the number of seconds.

ToTickString ( this time, StringBuilder sb ) : StringBuilder
ToTimeSpan ( [ str, System.TimeSpan &result ) : bool

Tries to create a TimeSpan from a string containing the number of seconds. If the string was empty, returns false and sets result to TimeSpan.Zero

ToTimeSpanLegacy ( this str, System.TimeSpan &result ) : bool
ToUnixTime ( this date ) : long

Converts a DateTime to UTC Unix Timestamp.

ToUnixTimeString ( this date, StringBuilder sb ) : StringBuilder

Appends a Utc Unix Timestamp to the given StringBuilder. If the date equals DateTime.MinValue, nothing is appended.

TryParseDateTime ( long timestamp ) : System.DateTime

Creates a DateTime from a UTC Unix Timestamp.

TryParseDateTime ( [ str, System.DateTime &result ) : bool

Tries to create a DateTime from a string containing a Utc Unix Timestamp. If the string was empty, returns false and does not affect result.

TryParseMiniTimeSpan ( [ text, System.TimeSpan &result ) : bool

Attempts to parse the given string as a TimeSpan in compact representation. No exception is thrown if parsing failed.

TryParseMiniTimespan ( [ text, System.TimeSpan &result ) : bool

Attempts to parse the given string as a TimeSpan in compact representation. No exception is thrown if parsing failed.

TryParseMiniTimespan ( this text, System.TimeSpan &result ) : bool
TryParseTimeSpan ( [ str, System.TimeSpan &result ) : bool

Tries to create a TimeSpan from a string containing the number of seconds. If the string was empty, returns false and sets result to TimeSpan.Zero

Private Methods

Method Description
DateTimeUtil ( ) : System
ToCompactString ( this date ) : string
ToDateTimeLegacy ( long timestamp ) : System.DateTime
ToDateTimeLegacy ( [ str, System.DateTime &result ) : bool
ToMiniString ( this span ) : string
ToSecondsString ( this time ) : string
ToTickString ( this time, [ sb ) : StringBuilder
ToTickString ( this time ) : string
ToTimeSpanLegacy ( [ str, System.TimeSpan &result ) : bool
ToUnixTimeLegacy ( this date ) : long
ToUnixTimeString ( this date, [ sb ) : StringBuilder
ToUnixTimeString ( this date ) : string
TryParseLocalDate ( [ dateString, System.DateTime &date ) : bool

Method Details

ParseMiniTimeSpan() public static method

Parses the given string as a TimeSpan in compact representation. Throws exceptions on failure.
text is null. The resulting TimeSpan is greater than TimeSpan.MaxValue. input has an invalid format.
public static ParseMiniTimeSpan ( [ text ) : System.TimeSpan
text [ String to parse.
return System.TimeSpan

ParseMiniTimespan() public static method

Parses the given string as a TimeSpan in compact representation. Throws exceptions on failure.
text is null. The resulting TimeSpan is greater than TimeSpan.MaxValue. input has an invalid format.
public static ParseMiniTimespan ( [ text ) : System.TimeSpan
text [ String to parse.
return System.TimeSpan

ToDateTime() public static method

Creates a DateTime from a UTC Unix Timestamp.
public static ToDateTime ( long timestamp ) : System.DateTime
timestamp long
return System.DateTime

ToDateTime() public static method

Creates a DateTime from a Utc Unix Timestamp.
public static ToDateTime ( this timestamp ) : System.DateTime
timestamp this
return System.DateTime

ToDateTime() public static method

Tries to create a DateTime from a string containing a Utc Unix Timestamp. If the string was empty, returns false and does not affect result.
public static ToDateTime ( this str, System.DateTime &result ) : bool
str this
result System.DateTime
return bool

ToDateTimeLegacy() public static method

public static ToDateTimeLegacy ( this str, System.DateTime &result ) : bool
str this
result System.DateTime
return bool

ToSeconds() public static method

public static ToSeconds ( this time ) : long
time this
return long

ToSecondsString() public static method

Serializes the given TimeSpan to the given StringBuilder, as the number of seconds.
sb is null.
public static ToSecondsString ( this time, [ sb ) : void
time this TimeSpan to serialize.
sb [ StringBuilder to which time will be saved.
return void

ToTickString() public static method

public static ToTickString ( this time, StringBuilder sb ) : StringBuilder
time this
sb StringBuilder
return StringBuilder

ToTimeSpan() public static method

Tries to create a TimeSpan from a string containing the number of seconds. If the string was empty, returns false and sets result to TimeSpan.Zero
public static ToTimeSpan ( [ str, System.TimeSpan &result ) : bool
str [
result System.TimeSpan
return bool

ToTimeSpanLegacy() public static method

public static ToTimeSpanLegacy ( this str, System.TimeSpan &result ) : bool
str this
result System.TimeSpan
return bool

ToUnixTime() public static method

Converts a DateTime to UTC Unix Timestamp.
public static ToUnixTime ( this date ) : long
date this
return long

ToUnixTimeString() public static method

Appends a Utc Unix Timestamp to the given StringBuilder. If the date equals DateTime.MinValue, nothing is appended.
public static ToUnixTimeString ( this date, StringBuilder sb ) : StringBuilder
date this
sb StringBuilder
return StringBuilder

TryParseDateTime() public static method

Creates a DateTime from a UTC Unix Timestamp.
public static TryParseDateTime ( long timestamp ) : System.DateTime
timestamp long
return System.DateTime

TryParseDateTime() public static method

Tries to create a DateTime from a string containing a Utc Unix Timestamp. If the string was empty, returns false and does not affect result.
public static TryParseDateTime ( [ str, System.DateTime &result ) : bool
str [
result System.DateTime
return bool

TryParseMiniTimeSpan() public static method

Attempts to parse the given string as a TimeSpan in compact representation. No exception is thrown if parsing failed.
text is null.
public static TryParseMiniTimeSpan ( [ text, System.TimeSpan &result ) : bool
text [ String to parse.
result System.TimeSpan Parsed TimeSpan. Set to TimeSpan.Zero if parsing failed.
return bool

TryParseMiniTimespan() public static method

Attempts to parse the given string as a TimeSpan in compact representation. No exception is thrown if parsing failed.
text is null.
public static TryParseMiniTimespan ( [ text, System.TimeSpan &result ) : bool
text [ String to parse.
result System.TimeSpan Parsed TimeSpan. Set to TimeSpan.Zero if parsing failed.
return bool

TryParseMiniTimespan() public static method

public static TryParseMiniTimespan ( this text, System.TimeSpan &result ) : bool
text this
result System.TimeSpan
return bool

TryParseTimeSpan() public static method

Tries to create a TimeSpan from a string containing the number of seconds. If the string was empty, returns false and sets result to TimeSpan.Zero
str is null
public static TryParseTimeSpan ( [ str, System.TimeSpan &result ) : bool
str [
result System.TimeSpan
return bool

Property Details

MaxTimeSpan public static property

Longest reasonable value that fCraft will allow to be entered for time spans (9999 days).
public static TimeSpan,System MaxTimeSpan
return System.TimeSpan

UnixEpoch public static property

UTC Unix epoch (1970-01-01, 00:00:00).
public static DateTime,System UnixEpoch
return System.DateTime