Date.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /* Representation for dates. */
  6. #ifndef mozilla_dom_Date_h
  7. #define mozilla_dom_Date_h
  8. #include "js/Date.h"
  9. #include "js/TypeDecls.h"
  10. namespace mozilla {
  11. namespace dom {
  12. class Date
  13. {
  14. public:
  15. Date() {}
  16. explicit Date(JS::ClippedTime aMilliseconds)
  17. : mMsecSinceEpoch(aMilliseconds)
  18. {}
  19. bool IsUndefined() const
  20. {
  21. return !mMsecSinceEpoch.isValid();
  22. }
  23. JS::ClippedTime TimeStamp() const
  24. {
  25. return mMsecSinceEpoch;
  26. }
  27. // Returns an integer in the range [-8.64e15, +8.64e15] (-0 excluded), *or*
  28. // returns NaN. DO NOT ASSUME THIS IS FINITE!
  29. double ToDouble() const
  30. {
  31. return mMsecSinceEpoch.toDouble();
  32. }
  33. void SetTimeStamp(JS::ClippedTime aMilliseconds)
  34. {
  35. mMsecSinceEpoch = aMilliseconds;
  36. }
  37. // Can return false if CheckedUnwrap fails. This will NOT throw;
  38. // callers should do it as needed.
  39. bool SetTimeStamp(JSContext* aCx, JSObject* aObject);
  40. bool ToDateObject(JSContext* aCx, JS::MutableHandle<JS::Value> aRval) const;
  41. private:
  42. JS::ClippedTime mMsecSinceEpoch;
  43. };
  44. } // namespace dom
  45. } // namespace mozilla
  46. #endif // mozilla_dom_Date_h