npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@adaskothebeast/http-params-processor-value-to-unix-timestamp

v12.0.0

Published

Unix second timestamp output strategy for HttpParamsProcessor date values.

Readme

⏱️ @adaskothebeast/http-params-processor-value-to-unix-timestamp

Unix timestamp output strategy for HttpParamsProcessor: dates as whole seconds since the epoch, for example 1704067200.

npm license

Core only, zero runtime dependencies. ESM + CJS. sideEffects: false.


📦 Install

npm i @adaskothebeast/http-params-processor-value-to-unix-timestamp @adaskothebeast/http-params-processor-core

🎯 What it does

This is a value-to strategy: the second half of the conversion pipeline. Pair it with a value-from strategy (-value-from-luxon, -value-from-dayjs, -value-from-moment, -value-from-js-joda, or the DefaultDateValueFromStrategy from core) using createValueConverter.

| Class | Serializes | Example output | | ------------------------------ | ---------- | -------------- | | UnixTimestampValueToStrategy | Date | 1704067200 |

This is the classic POSIX / time_t shape used by JWT exp/iat, most REST APIs written in Go, Python, PHP or Rust, and by anything that stores time as an integer column. It carries no time zone and no sub-second precision, so the value is unambiguous but lossy.


⚡ Usage

import { DefaultDateValueFromStrategy, ParamsProcessor, createValueConverter } from '@adaskothebeast/http-params-processor-core';
import { LuxonDateTimeValueFromStrategy } from '@adaskothebeast/http-params-processor-value-from-luxon';
import { UnixTimestampValueToStrategy } from '@adaskothebeast/http-params-processor-value-to-unix-timestamp';
import { DateTime } from 'luxon';

const processor = new ParamsProcessor({
  valueConverters: [
    createValueConverter(new LuxonDateTimeValueFromStrategy(), new UnixTimestampValueToStrategy()),
    // keep native Dates working too
    createValueConverter(new DefaultDateValueFromStrategy(), new UnixTimestampValueToStrategy()),
  ],
});

processor.process('p', {
  from: DateTime.fromISO('2024-01-01T00:00:00Z'),
  to: new Date('2024-06-15T14:30:45.000Z'),
});
// [['p.from', '1704067200'], ['p.to', '1718461845']]

Only dates are covered here. If the same request also carries durations or periods, register a converter for them with -value-to-iso or -value-to-nodatime.


🎛️ Options and formats

No constructor options - the output is always Math.floor(date.getTime() / 1000) rendered as a decimal string.

| Rule | Behaviour | | ----------------- | ---------------------------------------------------------------------------- | | Unit | Whole seconds since 1970-01-01T00:00:00Z | | Time zone | None. The instant is absolute, so the local offset never appears in output | | Sub-second digits | Discarded (Math.floor, so the value is rounded down, never rounded up) | | Type | string (a decimal integer, no quotes, no + sign) |

Because the truncation uses Math.floor and not Math.trunc, it always moves toward the past, on both sides of the epoch:

  • 2024-01-01T00:00:00.999Z1704067200 (the .999 is dropped),
  • 1969-12-31T23:59:59.500Z (getTime() is -500) → -1, not 0.

If your backend expects rounding to the nearest second, round the Date before it reaches the processor.


📤 Output examples

p.from=1704067200          # 2024-01-01T00:00:00.000Z
p.tail=1704067200          # 2024-01-01T00:00:00.999Z, milliseconds truncated
p.to=1718461845            # 2024-06-15T14:30:45.000Z
p.epoch=0                  # 1970-01-01T00:00:00.000Z
p.moon=-14182940           # 1969-07-20T20:17:40.000Z, pre-epoch dates are negative

⚠️ Edge cases

  • canHandle accepts only real Date instances. Strings such as '2024-01-01', already-numeric timestamps such as 1704067200, and null are rejected, so they fall through to the next converter and reach the default serialization untouched.
  • Invalid dates (new Date('invalid')) are rejected too, so a broken input never turns into NaN in the query string.
  • Sub-second precision is lost. Two instants inside the same second collapse to the same parameter value, which matters for cursor style pagination; use -value-to-ms-timestamp when you need milliseconds.
  • Pre-1970 dates serialize as negative integers. Some backends parse them into unsigned types and fail; verify before using this strategy for historical data.
  • The value is timezone agnostic by design. A parameter meant to be a local calendar day (a birthday, an invoice date) should not be a Unix timestamp, because the receiving side has no way to know which day you meant. Use -value-to-date-fns with yyyy-MM-dd for that.
  • Beyond 2038-01-19T03:14:07Z the value exceeds a signed 32-bit integer. JavaScript is fine with it, older backends are not.

🔗 Related packages

Full matrix and adapter recipes: main README.


📄 License

MIT © Adam Pluciński