/// <summary> /// Tries to parse a string into the DurationUnits enum /// </summary> /// <param name="unitsStr"></param> /// <returns>THe parsed value or the default value for DurationUnits enum (DurationUnits.Unknown)</returns> public static DurationUnits DurationUnitsParseOrDefault(string unitsStr) { DurationUnits units = default; if (Enum.TryParse <DurationUnits>(unitsStr, true, out var tmp)) { units = tmp; } return(units); }
/// <summary> /// Parse the specified string into a <see cref="Duration"/> /// </summary> /// <param name="s">The string representation to parse</param> /// <returns>A Duration represented by the string.</returns> public static Duration Parse(string s) { if (!IsParseStringValid(s)) { return(new Duration(0, DurationUnits.NOT_SET)); } string[] split = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); DurationUnits unit = ParseUnit(split[1]); if (float.TryParse(split[0], out float f)) { return(new Duration(f, unit)); } else { throw new FormatException($"The value portion of the input string [{split[0]}] could not be parsed into a number."); } }
/// <summary> /// Attempt to parse the specified string into a Duration. /// </summary> /// <param name="s">The string representation to parse.</param> /// <param name="duration">The parsed duration</param> /// <returns>A boolean indicating whether or not the string was successfully parsed</returns> public static bool TryParse(string s, out Duration duration) { if (!IsParseStringValid(s)) { duration = new Duration(0, DurationUnits.NOT_SET); return(false); } string[] split = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); DurationUnits unit = ParseUnit(split[1]); if (float.TryParse(split[0], out float f)) { duration = new Duration(f, unit); return(true); } duration = new Duration(0, unit); return(false); }
/// <inheritdoc/> public string ToDelimitedString() { CultureInfo culture = CultureInfo.CurrentCulture; return(string.Format( culture, StringHelper.StringFormatSequence(0, 11, Configuration.FieldSeparator), Id, SetIdAis.HasValue ? SetIdAis.Value.ToString(culture) : null, SegmentActionCode, UniversalServiceIdentifier?.ToDelimitedString(), StartDateTime.HasValue ? StartDateTime.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null, StartDateTimeOffset.HasValue ? StartDateTimeOffset.Value.ToString(Consts.NumericFormat, culture) : null, StartDateTimeOffsetUnits?.ToDelimitedString(), Duration.HasValue ? Duration.Value.ToString(Consts.NumericFormat, culture) : null, DurationUnits?.ToDelimitedString(), AllowSubstitutionCode, FillerStatusCode?.ToDelimitedString() ).TrimEnd(Configuration.FieldSeparator.ToCharArray())); }
/// <inheritdoc/> public string ToDelimitedString() { CultureInfo culture = CultureInfo.CurrentCulture; return(string.Format( culture, StringHelper.StringFormatSequence(0, 13, Configuration.FieldSeparator), Id, SetIdAil.HasValue ? SetIdAil.Value.ToString(culture) : null, SegmentActionCode, LocationResourceId != null ? string.Join(Configuration.FieldRepeatSeparator, LocationResourceId.Select(x => x.ToDelimitedString())) : null, LocationTypeAil?.ToDelimitedString(), LocationGroup?.ToDelimitedString(), StartDateTime.HasValue ? StartDateTime.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null, StartDateTimeOffset.HasValue ? StartDateTimeOffset.Value.ToString(Consts.NumericFormat, culture) : null, StartDateTimeOffsetUnits?.ToDelimitedString(), Duration.HasValue ? Duration.Value.ToString(Consts.NumericFormat, culture) : null, DurationUnits?.ToDelimitedString(), AllowSubstitutionCode?.ToDelimitedString(), FillerStatusCode?.ToDelimitedString() ).TrimEnd(Configuration.FieldSeparator.ToCharArray())); }
public DurationAttribute(DurationUnits units) { Units = units; }
///<summary>Sets the value of the <c><Duration></c> element.</summary> /// <param name="Units">Unit of time of the Duration value.</param> /// <param name="Value">Gets or sets the content value of the &lt;Duration&gt; element</param> ///<remarks> /// <para>This form of <c>setDuration</c> is provided as a convenience method /// that is functionally equivalent to the <c>Duration</c></para> /// <para>Version: 2.6</para> /// <para>Since: 1.5r1</para> /// </remarks> public void SetDuration(DurationUnits Units, string Value) { RemoveChild(InstrDTD.LESSON_DURATION); AddChild(InstrDTD.LESSON_DURATION, new Duration(Units, Value)); }
/// <summary> /// Create an instance of a Duration with the specified value and unit /// </summary> /// <param name="value">The numerical value of the duration.</param> /// <param name="unit">The unit of the duration</param> public Duration(float value, DurationUnits unit) { Value = value; Unit = unit; }
///<summary>Sets the value of the <c><Duration></c> element.</summary> /// <param name="Units">Unit of time of the Duration value.</param> /// <param name="Value">Gets or sets the content value of the &lt;Duration&gt; element</param> ///<remarks> /// <para>This form of <c>setDuration</c> is provided as a convenience method /// that is functionally equivalent to the <c>Duration</c></para> /// <para>Version: 2.6</para> /// <para>Since: 2.4</para> /// </remarks> public void SetDuration(DurationUnits Units, string Value) { RemoveChild(InstrDTD.CONTENTCATALOG_DURATION); AddChild(InstrDTD.CONTENTCATALOG_DURATION, new Duration(Units, Value)); }