fix(date): now supports date and time
This commit is contained in:
		| @@ -19,12 +19,13 @@ handle timeformats in smart ways | |||||||
| [](https://www.bithound.io/github/pushrocks/smarttime) | [](https://www.bithound.io/github/pushrocks/smarttime) | ||||||
| [](https://nodejs.org/dist/latest-v6.x/docs/api/) | [](https://nodejs.org/dist/latest-v6.x/docs/api/) | ||||||
| [](https://nodejs.org/dist/latest-v6.x/docs/api/) | [](https://nodejs.org/dist/latest-v6.x/docs/api/) | ||||||
| [](http://standardjs.com/) |  | ||||||
|  |  | ||||||
| ## Usage | ## Usage | ||||||
|  |  | ||||||
| Use TypeScript for best in class instellisense. | Use TypeScript for best in class instellisense. | ||||||
|  |  | ||||||
|  | Smarttime offers smart ways to deal with time. | ||||||
|  |  | ||||||
| For further information read the linked docs at the top of this README. | For further information read the linked docs at the top of this README. | ||||||
|  |  | ||||||
| > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) | > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) | ||||||
|   | |||||||
| @@ -7,4 +7,9 @@ tap.test('should create a valid JavaScript Date from European TimeStamp', async | |||||||
|   console.log(extendedDate); |   console.log(extendedDate); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | tap.test('should create a date and time with European Format', async () => { | ||||||
|  |   const extendedDate = smarttime.ExtendedDate.fromEuropeanDateAndTime('10.10.2018', '08:00:00', 'Europe/Berlin'); | ||||||
|  |   console.log(extendedDate); | ||||||
|  | }) | ||||||
|  |  | ||||||
| tap.start(); | tap.start(); | ||||||
|   | |||||||
| @@ -1,5 +1,7 @@ | |||||||
| import * as plugins from './smarttime.plugins'; | import * as plugins from './smarttime.plugins'; | ||||||
|  |  | ||||||
|  | export type TAvailableZone = 'Europe/Berlin'; | ||||||
|  |  | ||||||
| export class ExtendedDate extends Date { | export class ExtendedDate extends Date { | ||||||
|   public static fromEuropeanDate(europeanDate: string) { |   public static fromEuropeanDate(europeanDate: string) { | ||||||
|     const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDate); |     const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDate); | ||||||
| @@ -12,6 +14,16 @@ export class ExtendedDate extends Date { | |||||||
|     return new ExtendedDate(unixMilli); |     return new ExtendedDate(unixMilli); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** */ | ||||||
|  |   public static fromEuropeanDateAndTime(europeanDateArg: string, timeArg: string, zoneArg: TAvailableZone) { | ||||||
|  |     const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDateArg); | ||||||
|  |     const luxonDate = plugins.luxon.DateTime.fromISO(`${dateArray[3]}-${dateArray[2]}-${dateArray[1]}T${timeArg}`, { | ||||||
|  |       zone: zoneArg | ||||||
|  |     }); | ||||||
|  |     const unixMilli = luxonDate.toMillis(); | ||||||
|  |     return new ExtendedDate(unixMilli); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   constructor(unixMilli: number) { |   constructor(unixMilli: number) { | ||||||
|     super(unixMilli); |     super(unixMilli); | ||||||
|   } |   } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user