Compare commits

..

2 Commits

Author SHA1 Message Date
4a56527f7d 3.0.1 2018-10-21 12:12:45 +02:00
2a14d928a8 fix(date): now supports date and time 2018-10-21 12:12:44 +02:00
5 changed files with 21 additions and 3 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smarttime", "name": "@pushrocks/smarttime",
"version": "3.0.0", "version": "3.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,7 +1,7 @@
{ {
"name": "@pushrocks/smarttime", "name": "@pushrocks/smarttime",
"private": false, "private": false,
"version": "3.0.0", "version": "3.0.1",
"description": "handle timeformats in smart ways", "description": "handle timeformats in smart ways",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",

View File

@ -19,12 +19,13 @@ handle timeformats in smart ways
[![bitHound Code](https://www.bithound.io/github/pushrocks/smarttime/badges/code.svg)](https://www.bithound.io/github/pushrocks/smarttime) [![bitHound Code](https://www.bithound.io/github/pushrocks/smarttime/badges/code.svg)](https://www.bithound.io/github/pushrocks/smarttime)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) [![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) [![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](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)

View File

@ -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();

View File

@ -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);
} }