C# Class fCraft.DateTimeUtil

Provides utility functions for working with DateTime and TimeSpan.
Afficher le fichier Open project: fragmer/fCraft Class Usage Examples

Méthodes publiques

Свойство Type Description
MaxTimeSpan System.TimeSpan
UnixEpoch System.DateTime

Méthodes publiques

Méthode 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

Méthode 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 méthode

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.
Résultat System.TimeSpan

ParseMiniTimespan() public static méthode

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.
Résultat System.TimeSpan

ToDateTime() public static méthode

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

ToDateTime() public static méthode

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

ToDateTime() public static méthode

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
Résultat bool

ToDateTimeLegacy() public static méthode

public static ToDateTimeLegacy ( this str, System.DateTime &result ) : bool
str this
result System.DateTime
Résultat bool

ToSeconds() public static méthode

public static ToSeconds ( this time ) : long
time this
Résultat long

ToSecondsString() public static méthode

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.
Résultat void

ToTickString() public static méthode

public static ToTickString ( this time, StringBuilder sb ) : StringBuilder
time this
sb StringBuilder
Résultat StringBuilder

ToTimeSpan() public static méthode

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
Résultat bool

ToTimeSpanLegacy() public static méthode

public static ToTimeSpanLegacy ( this str, System.TimeSpan &result ) : bool
str this
result System.TimeSpan
Résultat bool

ToUnixTime() public static méthode

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

ToUnixTimeString() public static méthode

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
Résultat StringBuilder

TryParseDateTime() public static méthode

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

TryParseDateTime() public static méthode

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
Résultat bool

TryParseMiniTimeSpan() public static méthode

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.
Résultat bool

TryParseMiniTimespan() public static méthode

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.
Résultat bool

TryParseMiniTimespan() public static méthode

public static TryParseMiniTimespan ( this text, System.TimeSpan &result ) : bool
text this
result System.TimeSpan
Résultat bool

TryParseTimeSpan() public static méthode

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
Résultat bool

Property Details

MaxTimeSpan public_oe static_oe property

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

UnixEpoch public_oe static_oe property

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