Skip to content

Commit

Permalink
Merge pull request #221 from jecraig/issue-220/no-parsabledate-cstr
Browse files Browse the repository at this point in the history
Adding a generic ParsableDate constructor definition
  • Loading branch information
spencermountain authored Aug 15, 2020
2 parents 4eb51fa + 2a6814e commit bf23ffd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/types/constructor.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as test from 'tape'
import { spacetime } from './spacetime-static'
import { ParsableDate } from '../../types/types'

test('static api exists', (t: test.Test) => {
t.equal(typeof spacetime, 'function', 'default is a function')
Expand All @@ -22,5 +23,6 @@ test('constructor args work', (t: test.Test) => {
'accepts unit descriptor object'
)
t.equal(spacetime('2017-04-03').isValid(), true, 'accepts iso string')
t.equal(spacetime(<ParsableDate>'2017-04-03').isValid(), true, 'accepts datelike object')
t.end()
})
9 changes: 8 additions & 1 deletion types/constructors.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Spacetime } from './types'
import { Spacetime, ParsableDate } from './types'

export interface SpacetimeConstructorOptions {
/** javascript dates use millisecond-epochs, instead of second-epochs, like some other languages. This is a common bug, and by default spacetime warns if you set an epoch within January 1970. to disable set to true */
Expand Down Expand Up @@ -52,6 +52,13 @@ export interface SpacetimeConstructor {
* @param options Options for silencing warnings.
*/
(iso: string, timezone?: string, options?: SpacetimeConstructorOptions): Spacetime

/**
* @param parsableDate a parsable date like object
* @param timezone Optional timezone. If omitted uses the browser timezone.
* @param options Options for silencing warnings.
*/
(parsableDate: ParsableDate, timezone?: string, options?: SpacetimeConstructorOptions): Spacetime
}

export interface SpacetimeStatic extends SpacetimeConstructor {
Expand Down

0 comments on commit bf23ffd

Please sign in to comment.