TimeZoneInfo.AdjustmentRule.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * System.TimeZoneInfo.AdjustmentRule
  3. *
  4. * Author(s)
  5. * Stephane Delcroix <[email protected]>
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sublicense, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. using System.Runtime.Serialization;
  27. namespace System
  28. {
  29. public sealed partial class TimeZoneInfo {
  30. [SerializableAttribute]
  31. public sealed class AdjustmentRule : IEquatable<TimeZoneInfo.AdjustmentRule>, ISerializable, IDeserializationCallback
  32. {
  33. DateTime dateEnd;
  34. public DateTime DateEnd {
  35. get { return dateEnd; }
  36. }
  37. DateTime dateStart;
  38. public DateTime DateStart {
  39. get { return dateStart; }
  40. }
  41. TimeSpan daylightDelta;
  42. public TimeSpan DaylightDelta {
  43. get { return daylightDelta; }
  44. }
  45. TransitionTime daylightTransitionEnd;
  46. public TransitionTime DaylightTransitionEnd {
  47. get { return daylightTransitionEnd; }
  48. }
  49. TransitionTime daylightTransitionStart;
  50. public TransitionTime DaylightTransitionStart {
  51. get { return daylightTransitionStart; }
  52. }
  53. public static AdjustmentRule CreateAdjustmentRule (
  54. DateTime dateStart,
  55. DateTime dateEnd,
  56. TimeSpan daylightDelta,
  57. TransitionTime daylightTransitionStart,
  58. TransitionTime daylightTransitionEnd)
  59. {
  60. return new AdjustmentRule (dateStart, dateEnd, daylightDelta, daylightTransitionStart, daylightTransitionEnd);
  61. }
  62. private AdjustmentRule (
  63. DateTime dateStart,
  64. DateTime dateEnd,
  65. TimeSpan daylightDelta,
  66. TransitionTime daylightTransitionStart,
  67. TransitionTime daylightTransitionEnd)
  68. {
  69. if (dateStart.Kind != DateTimeKind.Unspecified || dateEnd.Kind != DateTimeKind.Unspecified)
  70. throw new ArgumentException ("the Kind property of dateStart or dateEnd parameter does not equal DateTimeKind.Unspecified");
  71. if (daylightTransitionStart == daylightTransitionEnd)
  72. throw new ArgumentException ("daylightTransitionStart parameter cannot equal daylightTransitionEnd parameter");
  73. if (dateStart.Ticks % TimeSpan.TicksPerDay != 0 || dateEnd.Ticks % TimeSpan.TicksPerDay != 0)
  74. throw new ArgumentException ("dateStart or dateEnd parameter includes a time of day value");
  75. if (dateEnd < dateStart)
  76. throw new ArgumentOutOfRangeException ("dateEnd is earlier than dateStart");
  77. if (daylightDelta > new TimeSpan (14, 0, 0) || daylightDelta < new TimeSpan (-14, 0, 0))
  78. throw new ArgumentOutOfRangeException ("daylightDelta is less than -14 or greater than 14 hours");
  79. if (daylightDelta.Ticks % TimeSpan.TicksPerSecond != 0)
  80. throw new ArgumentOutOfRangeException ("daylightDelta parameter does not represent a whole number of seconds");
  81. this.dateStart = dateStart;
  82. this.dateEnd = dateEnd;
  83. this.daylightDelta = daylightDelta;
  84. this.daylightTransitionStart = daylightTransitionStart;
  85. this.daylightTransitionEnd = daylightTransitionEnd;
  86. }
  87. public bool Equals (TimeZoneInfo.AdjustmentRule other)
  88. {
  89. return dateStart == other.dateStart &&
  90. dateEnd == other.dateEnd &&
  91. daylightDelta == other.daylightDelta &&
  92. daylightTransitionStart == other.daylightTransitionStart &&
  93. daylightTransitionEnd == other.daylightTransitionEnd;
  94. }
  95. public override int GetHashCode ()
  96. {
  97. return dateStart.GetHashCode () ^
  98. dateEnd.GetHashCode () ^
  99. daylightDelta.GetHashCode () ^
  100. daylightTransitionStart.GetHashCode () ^
  101. daylightTransitionEnd.GetHashCode ();
  102. }
  103. public void GetObjectData (SerializationInfo info, StreamingContext context)
  104. {
  105. throw new NotImplementedException ();
  106. }
  107. public void OnDeserialization (object sender)
  108. {
  109. throw new NotImplementedException ();
  110. }
  111. }
  112. }
  113. }