fromUnixTime.cjs 945 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. exports.fromUnixTime = fromUnixTime;
  3. var _index = require("./toDate.cjs");
  4. /**
  5. * The {@link fromUnixTime} function options.
  6. */
  7. /**
  8. * @name fromUnixTime
  9. * @category Timestamp Helpers
  10. * @summary Create a date from a Unix timestamp.
  11. *
  12. * @description
  13. * Create a date from a Unix timestamp (in seconds). Decimal values will be discarded.
  14. *
  15. * @param unixTime - The given Unix timestamp (in seconds)
  16. * @param options - An object with options. Allows to pass a context.
  17. *
  18. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  19. *
  20. * @returns The date
  21. *
  22. * @example
  23. * // Create the date 29 February 2012 11:45:05:
  24. * const result = fromUnixTime(1330515905)
  25. * //=> Wed Feb 29 2012 11:45:05
  26. */
  27. function fromUnixTime(unixTime, options) {
  28. return (0, _index.toDate)(unixTime * 1000, options?.in);
  29. }