BsonConstants.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright 2010-present MongoDB Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. using System;
  16. namespace MongoDB.Bson
  17. {
  18. /// <summary>
  19. /// A static class containing BSON constants.
  20. /// </summary>
  21. public static class BsonConstants
  22. {
  23. // private static fields
  24. private static readonly long __dateTimeMaxValueMillisecondsSinceEpoch;
  25. private static readonly long __dateTimeMinValueMillisecondsSinceEpoch;
  26. private static readonly DateTime __unixEpoch;
  27. // static constructor
  28. static BsonConstants()
  29. {
  30. // unixEpoch has to be initialized first
  31. __unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  32. __dateTimeMaxValueMillisecondsSinceEpoch = (DateTime.MaxValue - __unixEpoch).Ticks / 10000;
  33. __dateTimeMinValueMillisecondsSinceEpoch = (DateTime.MinValue - __unixEpoch).Ticks / 10000;
  34. }
  35. // public static properties
  36. /// <summary>
  37. /// Gets the number of milliseconds since the Unix epoch for DateTime.MaxValue.
  38. /// </summary>
  39. public static long DateTimeMaxValueMillisecondsSinceEpoch
  40. {
  41. get { return __dateTimeMaxValueMillisecondsSinceEpoch; }
  42. }
  43. /// <summary>
  44. /// Gets the number of milliseconds since the Unix epoch for DateTime.MinValue.
  45. /// </summary>
  46. public static long DateTimeMinValueMillisecondsSinceEpoch
  47. {
  48. get { return __dateTimeMinValueMillisecondsSinceEpoch; }
  49. }
  50. /// <summary>
  51. /// Gets the Unix Epoch for BSON DateTimes (1970-01-01).
  52. /// </summary>
  53. public static DateTime UnixEpoch { get { return __unixEpoch; } }
  54. }
  55. }