fromUnixTime.js 956 B

1234567891011121314151617181920212223242526272829303132
  1. import { toDate } from "./toDate.js";
  2. /**
  3. * The {@link fromUnixTime} function options.
  4. */
  5. /**
  6. * @name fromUnixTime
  7. * @category Timestamp Helpers
  8. * @summary Create a date from a Unix timestamp.
  9. *
  10. * @description
  11. * Create a date from a Unix timestamp (in seconds). Decimal values will be discarded.
  12. *
  13. * @param unixTime - The given Unix timestamp (in seconds)
  14. * @param options - An object with options. Allows to pass a context.
  15. *
  16. * @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).
  17. *
  18. * @returns The date
  19. *
  20. * @example
  21. * // Create the date 29 February 2012 11:45:05:
  22. * const result = fromUnixTime(1330515905)
  23. * //=> Wed Feb 29 2012 11:45:05
  24. */
  25. export function fromUnixTime(unixTime, options) {
  26. return toDate(unixTime * 1000, options?.in);
  27. }
  28. // Fallback for modularized imports:
  29. export default fromUnixTime;