TimeZoneInfo.AdjustmentRule.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. #if (INSIDE_CORLIB && (NET_4_0 || MOONLIGHT)) || (MOBILE && !INSIDE_CORLIB) || (NET_3_5 && !NET_4_0 && !BOOTSTRAP_NET_4_0)
  27. using System.Runtime.CompilerServices;
  28. using System.Runtime.Serialization;
  29. namespace System
  30. {
  31. public sealed partial class TimeZoneInfo {
  32. [SerializableAttribute]
  33. #if NET_4_0 || BOOTSTRAP_NET_4_0
  34. [TypeForwardedFrom (Consts.AssemblySystemCore_3_5)]
  35. #elif MOONLIGHT
  36. [TypeForwardedFrom (Consts.AssemblySystem_Core)]
  37. #endif
  38. public sealed class AdjustmentRule : IEquatable<TimeZoneInfo.AdjustmentRule>, ISerializable, IDeserializationCallback
  39. {
  40. DateTime dateEnd;
  41. public DateTime DateEnd {
  42. get { return dateEnd; }
  43. }
  44. DateTime dateStart;
  45. public DateTime DateStart {
  46. get { return dateStart; }
  47. }
  48. TimeSpan daylightDelta;
  49. public TimeSpan DaylightDelta {
  50. get { return daylightDelta; }
  51. }
  52. TransitionTime daylightTransitionEnd;
  53. public TransitionTime DaylightTransitionEnd {
  54. get { return daylightTransitionEnd; }
  55. }
  56. TransitionTime daylightTransitionStart;
  57. public TransitionTime DaylightTransitionStart {
  58. get { return daylightTransitionStart; }
  59. }
  60. public static AdjustmentRule CreateAdjustmentRule (
  61. DateTime dateStart,
  62. DateTime dateEnd,
  63. TimeSpan daylightDelta,
  64. TransitionTime daylightTransitionStart,
  65. TransitionTime daylightTransitionEnd)
  66. {
  67. return new AdjustmentRule (dateStart, dateEnd, daylightDelta, daylightTransitionStart, daylightTransitionEnd);
  68. }
  69. private AdjustmentRule (
  70. DateTime dateStart,
  71. DateTime dateEnd,
  72. TimeSpan daylightDelta,
  73. TransitionTime daylightTransitionStart,
  74. TransitionTime daylightTransitionEnd)
  75. {
  76. if (dateStart.Kind != DateTimeKind.Unspecified || dateEnd.Kind != DateTimeKind.Unspecified)
  77. throw new ArgumentException ("the Kind property of dateStart or dateEnd parameter does not equal DateTimeKind.Unspecified");
  78. if (daylightTransitionStart == daylightTransitionEnd)
  79. throw new ArgumentException ("daylightTransitionStart parameter cannot equal daylightTransitionEnd parameter");
  80. if (dateStart.Ticks % TimeSpan.TicksPerDay != 0 || dateEnd.Ticks % TimeSpan.TicksPerDay != 0)
  81. throw new ArgumentException ("dateStart or dateEnd parameter includes a time of day value");
  82. if (dateEnd < dateStart)
  83. throw new ArgumentOutOfRangeException ("dateEnd is earlier than dateStart");
  84. if (daylightDelta > new TimeSpan (14, 0, 0) || daylightDelta < new TimeSpan (-14, 0, 0))
  85. throw new ArgumentOutOfRangeException ("daylightDelta is less than -14 or greater than 14 hours");
  86. if (daylightDelta.Ticks % TimeSpan.TicksPerSecond != 0)
  87. throw new ArgumentOutOfRangeException ("daylightDelta parameter does not represent a whole number of seconds");
  88. this.dateStart = dateStart;
  89. this.dateEnd = dateEnd;
  90. this.daylightDelta = daylightDelta;
  91. this.daylightTransitionStart = daylightTransitionStart;
  92. this.daylightTransitionEnd = daylightTransitionEnd;
  93. }
  94. public bool Equals (TimeZoneInfo.AdjustmentRule other)
  95. {
  96. return dateStart == other.dateStart &&
  97. dateEnd == other.dateEnd &&
  98. daylightDelta == other.daylightDelta &&
  99. daylightTransitionStart == other.daylightTransitionStart &&
  100. daylightTransitionEnd == other.daylightTransitionEnd;
  101. }
  102. public override int GetHashCode ()
  103. {
  104. return dateStart.GetHashCode () ^
  105. dateEnd.GetHashCode () ^
  106. daylightDelta.GetHashCode () ^
  107. daylightTransitionStart.GetHashCode () ^
  108. daylightTransitionEnd.GetHashCode ();
  109. }
  110. #if NET_4_0
  111. void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
  112. #else
  113. public void GetObjectData (SerializationInfo info, StreamingContext context)
  114. #endif
  115. {
  116. throw new NotImplementedException ();
  117. }
  118. #if NET_4_0
  119. void IDeserializationCallback.OnDeserialization (object sender)
  120. #else
  121. public void OnDeserialization (object sender)
  122. #endif
  123. {
  124. throw new NotImplementedException ();
  125. }
  126. }
  127. }
  128. }
  129. #endif