DateObjectSerializer.js 656 B

123456789101112131415161718192021222324252627
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. /** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
  6. /** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
  7. class DateObjectSerializer {
  8. /**
  9. * @param {Date} obj date
  10. * @param {ObjectSerializerContext} context context
  11. */
  12. serialize(obj, context) {
  13. context.write(obj.getTime());
  14. }
  15. /**
  16. * @param {ObjectDeserializerContext} context context
  17. * @returns {Date} date
  18. */
  19. deserialize(context) {
  20. return new Date(context.read());
  21. }
  22. }
  23. module.exports = DateObjectSerializer;