date-time.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 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. "use strict";
  6. // Make this available to both AMD and CJS environments
  7. define(function (require, exports, module) {
  8. // ReactJS
  9. const React = require("devtools/client/shared/vendor/react");
  10. // Reps
  11. const { isGrip } = require("./rep-utils");
  12. // Shortcuts
  13. const { span } = React.DOM;
  14. /**
  15. * Used to render JS built-in Date() object.
  16. */
  17. let DateTime = React.createClass({
  18. displayName: "Date",
  19. propTypes: {
  20. object: React.PropTypes.object.isRequired
  21. },
  22. getTitle: function (grip) {
  23. if (this.props.objectLink) {
  24. return this.props.objectLink({
  25. object: grip
  26. }, grip.class + " ");
  27. }
  28. return "";
  29. },
  30. render: function () {
  31. let grip = this.props.object;
  32. let date;
  33. try {
  34. date = span({className: "objectBox"},
  35. this.getTitle(grip),
  36. span({className: "Date"},
  37. new Date(grip.preview.timestamp).toISOString()
  38. )
  39. );
  40. } catch (e) {
  41. date = span({className: "objectBox"}, "Invalid Date");
  42. }
  43. return date;
  44. },
  45. });
  46. // Registration
  47. function supportsObject(grip, type) {
  48. if (!isGrip(grip)) {
  49. return false;
  50. }
  51. return (type == "Date" && grip.preview);
  52. }
  53. // Exports from this module
  54. exports.DateTime = {
  55. rep: DateTime,
  56. supportsObject: supportsObject
  57. };
  58. });