Skip to content

Commit

Permalink
Fix formatInTimeZone types and fp
Browse files Browse the repository at this point in the history
  • Loading branch information
marnusw committed Dec 21, 2021
1 parent 36b410d commit 7206cef
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/formatInTimeZone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import utcToZonedTime from '../utcToZonedTime'
* @category Time Zone Helpers
* @summary Gets the offset in milliseconds between the time zone and Universal Coordinated Time (UTC)
*
* @param {Date|Number} date - the date representing the local time / real UTC time
* @param {Date|String|Number} date - the date representing the local time / real UTC time
* @param {String} timeZone - the time zone this date should be formatted for; can be an offset or IANA time zone
* @param {String} formatStr - the string of tokens
* @param {OptionsWithTZ} [options] - the object with options. See [Options]{@link https://date-fns.org/docs/Options}
* @param {0|1|2} [options.additionalDigits=2] - passed to `toDate`. See [toDate]{@link
* https://date-fns.org/docs/toDate}
Expand Down
7 changes: 6 additions & 1 deletion src/formatInTimeZone/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ type OptionsWithTZ = {
awareOfUnicodeTokens?: boolean,
}

declare module.exports: (date: Date | number, timeZone: string, options?: OptionsWithTZ) => string
declare module.exports: (
date: Date | string | number,
timeZone: string,
formatStr: string,
options?: OptionsWithTZ
) => string
2 changes: 1 addition & 1 deletion src/fp/formatInTimeZone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import fn from '../../formatInTimeZone/index.js'
import convertToFP from 'date-fns/fp/_lib/convertToFP/index.js'

var formatInTimeZone = convertToFP(fn, 2)
var formatInTimeZone = convertToFP(fn, 3)

export default formatInTimeZone
8 changes: 7 additions & 1 deletion src/fp/formatInTimeZone/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ type CurriedFn1<A, R> = <A>(a: A) => R

type CurriedFn2<A, B, R> = <A>(a: A) => CurriedFn1<B, R> | (<A, B>(a: A, b: B) => R)

declare module.exports: CurriedFn2<string, Date | number, string>
type CurriedFn3<A, B, C, R> = <A>(
a: A
) =>
| CurriedFn2<B, C, R>
| (<A, B>(a: A, b: B) => CurriedFn1<C, R> | (<A, B, C>(a: A, b: B, c: C) => R))

declare module.exports: CurriedFn3<string, string, Date | string | number, string>
2 changes: 1 addition & 1 deletion src/fp/formatInTimeZoneWithOptions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import fn from '../../formatInTimeZone/index.js'
import convertToFP from 'date-fns/fp/_lib/convertToFP/index.js'

var formatInTimeZoneWithOptions = convertToFP(fn, 3)
var formatInTimeZoneWithOptions = convertToFP(fn, 4)

export default formatInTimeZoneWithOptions
17 changes: 16 additions & 1 deletion src/fp/formatInTimeZoneWithOptions/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,19 @@ type CurriedFn3<A, B, C, R> = <A>(
| CurriedFn2<B, C, R>
| (<A, B>(a: A, b: B) => CurriedFn1<C, R> | (<A, B, C>(a: A, b: B, c: C) => R))

declare module.exports: CurriedFn3<OptionsWithTZ, string, Date | number, string>
type CurriedFn4<A, B, C, D, R> = <A>(
a: A
) =>
| CurriedFn3<B, C, D, R>
| (<A, B>(
a: A,
b: B
) =>
| CurriedFn2<C, D, R>
| (<A, B, C>(
a: A,
b: B,
c: C
) => CurriedFn1<D, R> | (<A, B, C, D>(a: A, b: B, c: C, d: D) => R)))

declare module.exports: CurriedFn4<OptionsWithTZ, string, string, Date | string | number, string>
10 changes: 8 additions & 2 deletions src/fp/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ type CurriedFn4<A, B, C, D, R> = <A>(

declare module.exports: {
format: CurriedFn2<string, Date | string | number, string>,
formatInTimeZone: CurriedFn2<string, Date | number, string>,
formatInTimeZoneWithOptions: CurriedFn3<OptionsWithTZ, string, Date | number, string>,
formatInTimeZone: CurriedFn3<string, string, Date | string | number, string>,
formatInTimeZoneWithOptions: CurriedFn4<
OptionsWithTZ,
string,
string,
Date | string | number,
string
>,
formatWithOptions: CurriedFn3<OptionsWithTZ, string, Date | string | number, string>,
getTimezoneOffset: CurriedFn2<Date | number, string, number>,
toDate: CurriedFn1<Date | string | number, Date>,
Expand Down
7 changes: 6 additions & 1 deletion src/index.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ type OptionsWithTZ = {
declare module.exports: {
format: (date: Date | string | number, format: string, options?: OptionsWithTZ) => string,

formatInTimeZone: (date: Date | number, timeZone: string, options?: OptionsWithTZ) => string,
formatInTimeZone: (
date: Date | string | number,
timeZone: string,
formatStr: string,
options?: OptionsWithTZ
) => string,

getTimezoneOffset: (timeZone: string, date?: Date | number) => number,

Expand Down
34 changes: 28 additions & 6 deletions typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ declare module 'date-fns-tz' {
function format(date: Date | string | number, format: string, options?: OptionsWithTZ): string
namespace format {}

function formatInTimeZone(date: Date | number, timeZone: string, options?: OptionsWithTZ): string
function formatInTimeZone(
date: Date | string | number,
timeZone: string,
formatStr: string,
options?: OptionsWithTZ
): string
namespace formatInTimeZone {}

function getTimezoneOffset(timeZone: string, date?: Date | number): number
Expand Down Expand Up @@ -171,10 +176,16 @@ declare module 'date-fns-tz/fp' {
const format: CurriedFn2<string, Date | string | number, string>
namespace format {}

const formatInTimeZone: CurriedFn2<string, Date | number, string>
const formatInTimeZone: CurriedFn3<string, string, Date | string | number, string>
namespace formatInTimeZone {}

const formatInTimeZoneWithOptions: CurriedFn3<OptionsWithTZ, string, Date | number, string>
const formatInTimeZoneWithOptions: CurriedFn4<
OptionsWithTZ,
string,
string,
Date | string | number,
string
>
namespace formatInTimeZoneWithOptions {}

const formatWithOptions: CurriedFn3<OptionsWithTZ, string, Date | string | number, string>
Expand Down Expand Up @@ -375,7 +386,12 @@ declare module 'date-fns-tz/esm' {
function format(date: Date | string | number, format: string, options?: OptionsWithTZ): string
namespace format {}

function formatInTimeZone(date: Date | number, timeZone: string, options?: OptionsWithTZ): string
function formatInTimeZone(
date: Date | string | number,
timeZone: string,
formatStr: string,
options?: OptionsWithTZ
): string
namespace formatInTimeZone {}

function getTimezoneOffset(timeZone: string, date?: Date | number): number
Expand Down Expand Up @@ -497,10 +513,16 @@ declare module 'date-fns-tz/esm/fp' {
const format: CurriedFn2<string, Date | string | number, string>
namespace format {}

const formatInTimeZone: CurriedFn2<string, Date | number, string>
const formatInTimeZone: CurriedFn3<string, string, Date | string | number, string>
namespace formatInTimeZone {}

const formatInTimeZoneWithOptions: CurriedFn3<OptionsWithTZ, string, Date | number, string>
const formatInTimeZoneWithOptions: CurriedFn4<
OptionsWithTZ,
string,
string,
Date | string | number,
string
>
namespace formatInTimeZoneWithOptions {}

const formatWithOptions: CurriedFn3<OptionsWithTZ, string, Date | string | number, string>
Expand Down

0 comments on commit 7206cef

Please sign in to comment.