/// <summary> /// Serializes this object's properties to XML. /// </summary> /// <param name="writer">Destination to write XML to.</param> public void WriteXml(XmlWriter writer) { if (writer is null) { throw new ArgumentNullException(nameof(writer)); } writer.WriteElementString("Hours24", Hours24.ToString("D", CultureInfo.InvariantCulture)); writer.WriteElementString("Minutes", Minutes.ToString("D", CultureInfo.InvariantCulture)); writer.WriteElementString("Seconds", Seconds.ToString("D", CultureInfo.InvariantCulture)); }
/// <summary> /// Convert to a string. /// </summary> /// <remarks> /// <para>If the format parameter consists of the single character "G" or "g", the string will consist of the value of the <see cref="AbsoluteSeconds"/> property.</para> /// <para>Otherwise, the following character sequences in the format parameter will be replaced as follows:</para> /// <list type="table"> /// <listheader> /// <term>Format character</term> /// <description>Replacement</description> /// </listheader> /// <item><term>f</term><description>If the seconds component of the time is 30 or greater, a half symbol; otherwise an empty string.</description></item> /// <item><term>h</term><description>Hours from 1-12, leading zeros omitted.</description></item> /// <item><term>hh</term><description>Hours from 01-12, leading zero preserved.</description></item> /// <item><term>H</term><description>Hours from 0-23, leading zeros omitted.</description></item> /// <item><term>HH</term><description>Hours from 00-23, leading zero preserved.</description></item> /// <item><term>m</term><descrption>Minutes from 0-59, leading zero omitted.</descrption></item> /// <item><term>mm</term><description>Minutes from 00-59, leading zero preserved.</description></item> /// <item><term>s</term><description>Seconds from 0-59, leading zero omitted.</description></item> /// <item><term>ss</term><description>Seconds from 00-59, leading zero preserved.</description></item> /// <item><term>t</term><description>The first letter of the AM/PM designator for the relevant culture.</description></item> /// <item><term>tt</term><description>The AM/PM designator for the relevant culture.</description></item> /// </list> /// </remarks> /// <param name="format">Format string</param> /// <param name="formatProvider">Culture-specific information.</param> /// <returns>A string containing the value of the object formatted as per the format string and culture.</returns> public string ToString(string format, IFormatProvider formatProvider) { if (format is null) { throw new ArgumentNullException(nameof(format)); } if (format == "g" || format == "G") { return(AbsoluteSeconds.ToString(formatProvider)); } format = format.Replace("hh", Hours12.ToString("d2", formatProvider)); format = format.Replace("h", Hours12.ToString(formatProvider)); format = format.Replace("HH", Hours24.ToString("d2", formatProvider)); format = format.Replace("H", Hours24.ToString(formatProvider)); format = format.Replace("mm", Minutes.ToString("d2", formatProvider)); format = format.Replace("m", Minutes.ToString(formatProvider)); format = format.Replace("ss", Seconds.ToString("d2", formatProvider)); format = format.Replace("s", Seconds.ToString(formatProvider)); format = format.Replace("f", Seconds >= 30 ? "½" : string.Empty); if (format.Contains("t")) { string desig = GetDesignator(formatProvider, false); format = format.Replace("tt", desig); if (!desig.Contains("t")) { format = format.Replace("t", desig.Substring(0, 1)); } } if (format.Contains("T")) { string desig = GetDesignator(formatProvider, true); format = format.Replace("TT", desig); if (!desig.Contains("T")) { format = format.Replace("T", desig.Substring(0, 1)); } } return(format); }
public void IsUsed_SingleValueMatch() { Assert.IsTrue(Hours24.HasAny(Hours24)); }
public static decimal TestCalculateFee(DateTime startTime, DateTime endTime, string feeRuleId) { IParkFeeRule factory = ParkFeeRuleFactory.GetFactory(); ParkFeeRule rule = factory.QueryParkFeeRuleByFeeRuleId(feeRuleId); if (rule == null) { throw new MyException("获取规则失败"); } switch (rule.FeeType) { case FeeType.DayAndNight: { IFeeRule IFee = new DayNight(); IFee.ParkingBeginTime = startTime; IFee.ParkingEndTime = endTime; IFee.FeeRule = rule; IFee.listRuleDetail = rule.ParkFeeRuleDetails; return(IFee.CalcFee()); } case FeeType.Hour12: { IFeeRule IFee = new Hours12(); IFee.ParkingBeginTime = startTime; IFee.ParkingEndTime = endTime; IFee.FeeRule = rule; IFee.listRuleDetail = rule.ParkFeeRuleDetails; return(IFee.CalcFee()); } case FeeType.Hour24: { IFeeRule IFee = new Hours24(); IFee.ParkingBeginTime = startTime; IFee.ParkingEndTime = endTime; IFee.FeeRule = rule; IFee.listRuleDetail = rule.ParkFeeRuleDetails; return(IFee.CalcFee()); } case FeeType.NaturalDay: { IFeeRule IFee = new NaturalDay(); IFee.ParkingBeginTime = startTime; IFee.ParkingEndTime = endTime; IFee.FeeRule = rule; IFee.listRuleDetail = rule.ParkFeeRuleDetails; return(IFee.CalcFee()); } case FeeType.Custom: { IFeeRule IFee = new Userdefined2(); IFee.ParkingBeginTime = startTime; IFee.ParkingEndTime = endTime; IFee.FeeRule = rule; IFee.FeeText = rule.RuleText; return(IFee.CalcFee()); } default: throw new MyException("算费规则不存在"); } }