C# Class WizardWrx.SysDateFormatters

This class implements my stalwart date formatter, ReformatSysDateP6C, which I created initially as a Windows Interface Language (WIL, a. k. a. WinBatch) library function, Reformat_Date_YmdHms_P6C, in October 2001, although its roots go back much further in my WIL script development. Since static classes are implicitly sealed, this class cannot be inherited.
Mostrar archivo Open project: txwizard/WizardWrx_NET_API Class Usage Examples

Public Properties

Property Type Description
RSD_TOKENS string[]

Public Methods

Method Description
FormatDateForShow ( DateTime pdtmTestDate ) : string

Use my standard format string for displaying date stamps in reports, to format a DateTime structure.

FormatDateTimeForShow ( DateTime pdtmTestDate ) : string

Use my standard format string for displaying date/time stamps in reports, to format a DateTime structure.

FormatTimeForShow ( DateTime pdtmTestDate ) : string

Use my standard format string for displaying time stamps in reports, to format a DateTime structure.

GetDisplayTimeZone ( DateTime pdtmTestDate, string pstrTimeZoneID, bool pfAbbreviateTZName = false ) : string

Given a DateTime and a system time zone ID string, return the appropriate text to display, depending on whether the specified time is standard or Daylight Saving Time.

if in doubt, use TimeZoneInfo.GetSystemTimeZones to enumerate the time zones installed on the local machine. Invalid time zone strings always give rise to one of a number of exceptions, all of which are fully described in the documentation of a companion function, GetSystemTimeZoneInfo which this routine uses to get the time zone information that it needs.

GetSystemTimeZoneInfo ( string pstrTimeZoneID ) : TimeZoneInfo

Given a system time zone ID string, return the corresponding TimeZoneInfo object if the specified time zone is defined on the local system.

if in doubt, use TimeZoneInfo.GetSystemTimeZones to enumerate the time zones installed on the local machine.

ReformatNow ( string pstrFormat ) : string

This method has a nearly exact analogue in the constellations of WIL User Defined Functions that gave rise to its immediate predecessor, a like named function implemented in straight C, with a little help from the Windows National Language Subsystem, which underlies the CultureInfo class.

ReformatSysDate ( DateTime pdtmToFormat, string pstrFormat ) : string

ReformatSysDate is the core function of the constellation of routines that grew from the original WIL script. Substitution tokens drive construction of a formatted date string.

ReformatUtcNow ( string pstrFormat ) : string

In the original constellation of WinBatch functions and their C descendants, this function took the form of an optional argument to ReformatNow. I think I prefer this way.

Private Methods

Method Description
EstimateFinalLength ( string &pstrFormat ) : int
SysDateFormatters ( ) : System

Method Details

FormatDateForShow() public static method

Use my standard format string for displaying date stamps in reports, to format a DateTime structure.
public static FormatDateForShow ( DateTime pdtmTestDate ) : string
pdtmTestDate DateTime /// Specify the populated DateTime to be formatted. Since only the date /// goes into the format, the time component MAY be uninitialized. ///
return string

FormatDateTimeForShow() public static method

Use my standard format string for displaying date/time stamps in reports, to format a DateTime structure.
public static FormatDateTimeForShow ( DateTime pdtmTestDate ) : string
pdtmTestDate DateTime /// Specify the populated DateTime to be formatted. Since the date and /// time go into the output string, the entire structure must be /// initialized. ///
return string

FormatTimeForShow() public static method

Use my standard format string for displaying time stamps in reports, to format a DateTime structure.
public static FormatTimeForShow ( DateTime pdtmTestDate ) : string
pdtmTestDate DateTime /// Specify the populated DateTime to be formatted. Since only the time /// goes into the format, the date component MAY be uninitialized. ///
return string

GetDisplayTimeZone() public static method

Given a DateTime and a system time zone ID string, return the appropriate text to display, depending on whether the specified time is standard or Daylight Saving Time.
if in doubt, use TimeZoneInfo.GetSystemTimeZones to enumerate the time zones installed on the local machine. Invalid time zone strings always give rise to one of a number of exceptions, all of which are fully described in the documentation of a companion function, GetSystemTimeZoneInfo which this routine uses to get the time zone information that it needs.
public static GetDisplayTimeZone ( DateTime pdtmTestDate, string pstrTimeZoneID, bool pfAbbreviateTZName = false ) : string
pdtmTestDate DateTime /// Specify the Syatem.DateTime for which the appropriate time zone /// string is required. Both DateTime.MinValue and DateTime.MaxValue are /// invalid; specifying either elicits the empty string. ///
pstrTimeZoneID string /// Specify a valid time zone ID string. Please see the Remarks. ///
pfAbbreviateTZName bool /// /// Specify TZ_NAME_ABBR (Boolean True) to cause the method to return /// the abbreviated time zone name that it constructs from the full /// (spelled out) name that is the system default. /// /// /// You may also specify TZ_NAME_FULL to explicitly cause the full time /// zone name to be returned. /// /// /// If this argument is omitted, the full time zone name is returned, so /// that this method is backwards compatible. /// ///
return string

GetSystemTimeZoneInfo() public static method

Given a system time zone ID string, return the corresponding TimeZoneInfo object if the specified time zone is defined on the local system.
if in doubt, use TimeZoneInfo.GetSystemTimeZones to enumerate the time zones installed on the local machine.
/// You should restart Windows if this happens. /// /// Contact the author of the program. This is something that he or she /// must address. /// /// Contact the author of the program. This is something that he or she /// must address. /// /// Contact your system administrator to inquire about why your program /// is forbidden to read the regional settings from the Windows /// Registry. /// /// Contact your system support group. A corrupted Windows Registry is a /// rare, but serious matter. /// /// Start with your system support group, who may need to request the /// assistance of the author of the program. ///
public static GetSystemTimeZoneInfo ( string pstrTimeZoneID ) : TimeZoneInfo
pstrTimeZoneID string /// Specify a valid time zone ID string. There are two special IDs, /// LocalTime and UTC, both of which are accessible through static /// properties on the TimeZoneInfo class. Although you could use the ID /// properties with this method, the most efficient way to handle these /// special cases is by reference to the Local property for LocalTime /// and the UTC property for UTC time. (This method could take the same /// shortcut, but I decided that it wasn't worth the extra code and /// testing. ///
return TimeZoneInfo

ReformatNow() public static method

This method has a nearly exact analogue in the constellations of WIL User Defined Functions that gave rise to its immediate predecessor, a like named function implemented in straight C, with a little help from the Windows National Language Subsystem, which underlies the CultureInfo class.
public static ReformatNow ( string pstrFormat ) : string
pstrFormat string /// This System.String is a combination of tokens and literal text that /// governs the formatting of the date. ///
return string

ReformatSysDate() public static method

ReformatSysDate is the core function of the constellation of routines that grew from the original WIL script. Substitution tokens drive construction of a formatted date string.
public static ReformatSysDate ( DateTime pdtmToFormat, string pstrFormat ) : string
pdtmToFormat DateTime /// This System.DateTime is the time to be formatted. ///
pstrFormat string /// This System.String is a combination of tokens and literal text that /// governs the formatting of the date. ///
return string

ReformatUtcNow() public static method

In the original constellation of WinBatch functions and their C descendants, this function took the form of an optional argument to ReformatNow. I think I prefer this way.
public static ReformatUtcNow ( string pstrFormat ) : string
pstrFormat string /// This System.String is a combination of tokens and literal text that /// governs the formatting of the date. ///
return string

Property Details

RSD_TOKENS public_oe static_oe property

The strings in this array are the substitution tokens supported by the date formatters in this class.
public static string[] RSD_TOKENS
return string[]