1.2.0 • Published 1 year ago

http-dates v1.2.0

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
1 year ago

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.

1.2.0

1 year ago

1.1.3

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.2

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.0-3

2 years ago