AcUtils
A high performance abstraction layer for AccuRev
AcDateTime.cs
Go to the documentation of this file.
1 
16 using System;
17 using System.Globalization;
18 
19 namespace AcUtils
20 {
24  [Serializable]
25  public static class AcDateTime
26  {
27  #region class variables
28  private static CultureInfo _ci;
29  #endregion
30 
34  static AcDateTime()
35  {
36  _ci = new CultureInfo("en-US");
37  }
38 
44 
45  public static string DateTime2AcDate(DateTime? dt)
46  {
47  string val = (dt == null) ? String.Empty :
48  dt.Value.ToString("yyyy\\/MM\\/dd HH\\:mm\\:ss", CultureInfo.InvariantCulture);
49  return val;
50  }
51 
60 
61  public static DateTime? AcDate2DateTime(long seconds)
62  {
63  DateTime? dt = null;
64  try
65  {
66  if (seconds > 0)
67  {
68  DateTimeOffset dto = DateTimeOffset.FromUnixTimeSeconds(seconds);
69  dt = dto.DateTime.ToLocalTime();
70  }
71  }
72 
73  catch (ArgumentOutOfRangeException ecx)
74  {
75  AcDebug.Log($"ArgumentOutOfRangeException caught and logged in AcDateTime.AcDate2DateTime{Environment.NewLine}{ecx.Message}");
76  }
77 
78  return dt;
79  }
80 
86  public static DateTime? AcDate2DateTime(string seconds)
87  {
88  long val;
89  bool result = long.TryParse(seconds, out val);
90  return (result) ? AcDate2DateTime(val) : null;
91  }
92 
98 
99  public static bool AcDateValid(string dt)
100  {
101  DateTime temp;
102  return DateTime.TryParseExact(dt, "yyyy\\/MM\\/dd HH\\:mm\\:ss", _ci, DateTimeStyles.None, out temp);
103  }
104  }
105 }
static DateTime AcDate2DateTime(string seconds)
Convert an AccuRev date given in Unix time (seconds param) to a .NET DateTime in local time...
Definition: AcDateTime.cs:86
static AcDateTime()
Instantiate CultureInfo class variable.
Definition: AcDateTime.cs:34
Use to validate and convert date/time values to and from .NET and AccuRev/Unix formats.
Definition: AcDateTime.cs:25
static DateTime AcDate2DateTime(long seconds)
Convert an AccuRev date given in Unix time (seconds param) to a .NET DateTime in local time...
Definition: AcDateTime.cs:61
static void Log(string message, bool formatting=true)
Write the message text to STDOUT, to weekly log files located in %LOCALAPPDATA%\AcTools\Logs, and to trigger.log in the AccuRev server's ..storage\site_slice\logs folder in the case of triggers.
Definition: AcDebug.cs:378
static string DateTime2AcDate(DateTime?dt)
Convert DateTime dt parameter to a string suitable for AccuRev command line processing.
Definition: AcDateTime.cs:45
Use to log and display error and general purpose text messages, and to save the XML param data sent b...
Definition: AcDebug.cs:100
static bool AcDateValid(string dt)
Determine if dt parameter in AccuRev string format is a valid date and time.
Definition: AcDateTime.cs:99