blind-date
Advanced tools
Comparing version
@@ -9,3 +9,3 @@ declare type Opaque<K, T> = T & { | ||
export declare type OffsetDateTimeString = Opaque<'OffsetDateTimeString', string>; | ||
export interface LiteralDate { | ||
export interface LiteralLocalDate { | ||
year: number; | ||
@@ -15,3 +15,3 @@ month: number; | ||
} | ||
export interface LiteralTime { | ||
export interface LiteralLocalTime { | ||
hours: number; | ||
@@ -22,6 +22,6 @@ minutes: number; | ||
} | ||
export interface LiteralDateTime extends LiteralDate, LiteralTime { | ||
export interface LiteralLocalDateTime extends LiteralLocalDate, LiteralLocalTime { | ||
day: number; | ||
} | ||
export interface LiteralOffsetDateTime extends LiteralDateTime { | ||
export interface LiteralOffsetDateTime extends LiteralLocalDateTime { | ||
/** Timezone offset in minutes */ | ||
@@ -52,3 +52,3 @@ offset: number; | ||
export declare function isOffsetDateTimeString(date: unknown): date is LocalDateString; | ||
export declare type DateLike = string | MomentOrDayjsLike | DateTimeLike | Date | LiteralDate | LiteralDateTime | LiteralTime | LiteralOffsetDateTime; | ||
export declare type DateLike = string | MomentOrDayjsLike | DateTimeLike | Date | LiteralLocalDate | LiteralLocalDateTime | LiteralLocalTime | LiteralOffsetDateTime; | ||
export declare function toLocalDateTimeString(date: DateLike): LocalDateTimeString; | ||
@@ -55,0 +55,0 @@ export declare function toLocalDateTimeString(year: number, month: number, day: number, hours: number, minutes: number, seconds?: number, milliseconds?: number): LocalDateTimeString; |
{ | ||
"name": "blind-date", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "", | ||
@@ -9,4 +9,8 @@ "main": "dist/index.js", | ||
"build": "tsc -p tsconfig.prod.json", | ||
"prepare": "npm run build && npm test", | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm run test:all", | ||
"test": "jest", | ||
"test:all": "npm run test:nz && npm run test:us", | ||
"test:nz": "TZ=Pacific/Auckland jest", | ||
"test:us": "TZ=America/Los_Angeles jest", | ||
"watch": "tsc --watch" | ||
@@ -25,2 +29,3 @@ }, | ||
"jest": "^27.0.6", | ||
"luxon": "^2.0.1", | ||
"moment": "^2.29.1", | ||
@@ -27,0 +32,0 @@ "ts-jest": "^27.0.3", |
@@ -13,6 +13,9 @@ # Blind Date | ||
Example: | ||
```typescript | ||
import { toLocalDateString, toLocalTimeString, toOffsetDateTimeString, toLocalDateTimeString, LocalDateTimeString, LocalDateString, LocalTimeString, OffsetDateTimeString } from 'blind-date' | ||
``` | ||
### with Moment.js | ||
```typescript | ||
import { toLocalDateString, toLocalTimeString, toOffsetDateTimeString, toLocalDateTimeString, LocalDateTimeString, LocalDateString, LocalTimeString, OffsetDateTimeString } from '..' | ||
import moment from 'moment' | ||
@@ -22,18 +25,51 @@ | ||
const localDate: LocalDateString = toLocalDateString(exampleMoment) | ||
// 2021-01-22 | ||
const localDate: LocalDateString = toLocalDateString(exampleMoment) // 2021-01-22 | ||
const localDateTime: LocalDateTimeString = toLocalDateTimeString(exampleMoment) | ||
// 2021-01-22T13:57:00 | ||
const localDateTime: LocalDateTimeString = toLocalDateTimeString(exampleMoment) // 2021-01-22T13:57:00 | ||
const localTime: LocalTimeString = toLocalTimeString(exampleMoment) | ||
// 13:57:00 | ||
const localTime: LocalTimeString = toLocalTimeString(exampleMoment) // 13:57:00 | ||
const offsetDateTime: OffsetDateTimeString = toOffsetDateTimeString(exampleMoment) | ||
// 2021-01-22T13:57:00+13:00 | ||
const offsetDateTime: OffsetDateTimeString = toOffsetDateTimeString(exampleMoment) // 2021-01-22T13:57:00+13:00 | ||
``` | ||
const offsetDateTime2: OffsetDateTimeString = toOffsetDateTimeString('2021-01-22T13:57:00-08:00') | ||
// 2021-01-22T13:57:00-08:00 | ||
### with strings | ||
```typescript | ||
const localDate: LocalDateString = toLocalDateString('2021-01-22') | ||
const localDateTime: LocalDateTimeString = toLocalDateTimeString('2021-01-22T13:57:00') | ||
const localTime: LocalTimeString = toLocalTimeString('13:57:00') | ||
const offsetDateTime: OffsetDateTimeString = toOffsetDateTimeString('2021-01-22T13:57:00-08:00') | ||
``` | ||
### with literal values | ||
```typescript | ||
const localDate: LocalDateString = toLocalDateString(2021, 1, 22) // 2021-01-22 | ||
const localDateTime: LocalDateTimeString = toLocalDateTimeString(2021, 1, 22, 13, 57, 0) // 2021-01-22T13:57:00 | ||
const localTime: LocalTimeString = toLocalTimeString(13, 57) // 13:57:00 | ||
const offsetDateTime: OffsetDateTimeString = toOffsetDateTimeString(2021, 1, 22, 13, 57, 0, 0, -480) // 2021-01-22T13:57:00-08:00 | ||
``` | ||
Or more explicitly: | ||
```typescript | ||
const localDate: LocalDateString = toLocalDateString({ year: 2021, month: 1, day: 22 }) // 2021-01-22 | ||
const localDateTime: LocalDateTimeString = toLocalDateTimeString({ | ||
year: 2021, month: 1, day: 22, hours: 13, minutes: 57 | ||
}) // 2021-01-22T13:57:00 | ||
const localTime: LocalTimeString = toLocalTimeString({ hours: 13, minutes: 57 }) // 13:57:00 | ||
const offsetDateTime: OffsetDateTimeString = toOffsetDateTimeString({ | ||
year: 2021, month: 1, day: 22, hours: 13, minutes: 57, offset: -480 | ||
}) // 2021-01-22T13:57:00-08:00 | ||
``` | ||
## Compatibility | ||
@@ -40,0 +76,0 @@ |
33453
47.64%14
250%565
38.48%152
31.03%12
9.09%