Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

http-dates

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-dates

parse RFC 7231 HTTP-dates with this zero-dependency ultra slim lib

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

npm version package size test coverage

http-dates

Ultra slim, zero-dependency library for parsing HTTP-dates according to RFC 7231, Section 7.1.1.1. E.g. as being used in Last-Modified and If-Unmodified-Since headers. All the described formats are being parsed for full backwards compatibility

Installation

npm i http-dates

Usage

Just parse your HTTP header content (or wherever you get the HTTP-date formatted string from) like:

import parseHTTPdate from 'http-dates';

// IMF-fixdate for 1994-11-06T08:49:37.000Z
parseHTTPdate('Sun, 06 Nov 1994 08:49:37 GMT');

// rfc850-date for 1994-11-06T08:49:37.000Z
// NOTE: next line will not work from November 7th 2044 (see deprecation notes below)
parseHTTPdate('Sunday, 06-Nov-94 08:49:37 GMT');

// asctime-date 1994-11-06T08:49:37.000Z
parseHTTPdate('Sun Nov  6 08:49:37 1994');

Deprecation notes

asctime-date

ANSI C's asctime() format is deprecated for legacy reasons.

rfc850-date

The use of RFC 850 date format is highly discouraged as it is a relative date format. RFC 7231 states:

Recipients of a timestamp value in rfc850-date format, which uses a two-digit year, MUST interpret a timestamp that appears to be more than 50 years in the future as representing the most recent year in the past that had the same last two digits.

Thsi is being handled by the library, leading to indeterministic parsing results: If your parse a RFC 850 date string 'Tuesday, 06-Nov-73 08:49:37 GMT' today (March 2022) it returns a Date in 1973 (1973-11-06T08:49:37.000Z). If you repeat the same call in 2024 it would parse it as a date in 2073 (2073-11-06T08:49:37.000Z). but it will NOT, because that day is a not Tuesday, so it will throw a HTTPdateParseError.

Keywords

FAQs

Package last updated on 08 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc