1.1.2 • Published 7 years ago

date-test-helpers v1.1.2

Weekly downloads
133
License
MIT
Repository
-
Last release
7 years ago

date-test-helpers Build Status

Create Date objects out of strings represented in common American timezones. The intention of this module is for it to be used to create stub test data, not for it to be used in production code, but, y'know, do what you want.

Example

import dateTestHelpers from 'date-test-helpers';

console.log(dateTestHelpers.pacific.startOfDay('1954-08-02'))
/* output: Sun Aug 02 1954 00:00:00 GMT-0700 (PDT) */

console.log(dateTestHelpers.pacific.time('2016-04-02 14:00:00'))
/* output: Sat Apr 02 2016 14:00:00 GMT-0700 (PDT) */

Documentation

date-test-helpers exports the following objects, each representing a timezone:

Object NameTimezone
pacificAmerica/Los_Angeles
mountainAmerica/Denver
centralAmerica/Chicago
easternAmerica/New_York
utcutc

Each object contains the following methods:

  • startOfDay('YYYY-MM-DD'): Date
  • time('YYYY-MM-DD HH:mm:ss'): Date

Passing in a string with any other format will throw a TypeError. Hours should be represented using 24-hour (military) time. All parsing and timezone math is handled by the comprehensive moment.js library.

Contributing

I aim to keep this module very small and single-purpose. If you find a bug, please let me know by opening an issue! If you'd like to submit a pull-request, please check that all tests pass, and if you're adding new functionality or fixing a bug, please add more test coverage!

You can run tests with:

yarn test
1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago