// Summary: // Converts the specified string representation of a date and time to its System.DateTime // equivalent using the specified array of formats, culture-specific format // information, and style. The format of the string representation must match // at least one of the specified formats exactly. The method returns a value // that indicates whether the conversion succeeded. // // Parameters: // s: // A string containing one or more dates and times to convert. // // formats: // An array of allowable formats of s. // // provider: // An object that supplies culture-specific format information about s. // // style: // A bitwise combination of enumeration values that indicates the permitted // format of s. A typical value to specify is System.Globalization.DateTimeStyles.None. // // result: // When this method returns, contains the System.DateTime value equivalent to // the date and time contained in s, if the conversion succeeded, or System.DateTime.MinValue // if the conversion failed. The conversion fails if s or formats is null, s // or an element of formats is an empty string, or the format of s is not exactly // as specified by at least one of the format patterns in formats. This parameter // is passed uninitialized. // // Returns: // true if the s parameter was converted successfully; otherwise, false. // // Exceptions: // System.ArgumentException: // styles is not a valid System.Globalization.DateTimeStyles value.-or-styles // contains an invalid combination of System.Globalization.DateTimeStyles values // (for example, both System.Globalization.DateTimeStyles.AssumeLocal and System.Globalization.DateTimeStyles.AssumeUniversal). public static bool TryParseExact(string s, string[] formats, IFormatProvider provider, DateTimeStyles style, out Timestamp result) { DateTime dt; try { dt = DateTime.ParseExact(s, formats, provider, style); result = new Timestamp(Timestamp.DateTimeToUnixTimestamp(dt)); return(true); } catch { result = new Timestamp(0); return(false); } }
public StepInfo AddStep(StepInfo step) { StepInfo newStep, oldStep = null; string id = ReporterManager.GenerateStepId(); newStep = new StepInfo(step.Description) { Actual = step.Actual, Expected = step.Expected, Attachments = step.Attachments, ExtraInfo = step.ExtraInfo, Messages = step.Messages, Name = step.Name, StartTime = Timestamp.DateTimeToUnixTimestamp(DateTime.UtcNow), Id = id, // Convert.ToString(this.Steps.Count + 1), Section = $"{this.Section}/step[@id='{id}']", // $"{this.Section}/step[{this.Steps.Count + 1}]", }; if (String.IsNullOrEmpty(step.Name)) { newStep.Name = GetStepName(); } newStep.StatusChanged += Step_StatusChanged; newStep.Outcome = step.Outcome; if (this.Steps.Count > 0) { oldStep = this.Steps[this.Steps.Count - 1]; } this.Steps.Add(newStep); OnStepAdded(newStep, oldStep); return(newStep); }
public void SetEndTime(DateTime value) { _endTime = new Timestamp(Timestamp.DateTimeToUnixTimestamp(value.ToUniversalTime())); }