Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
6bca8557f9 | |||
f0a5e18335 | |||
57fbdb4a70 | |||
4a56527f7d | |||
2a14d928a8 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarttime",
|
"name": "@pushrocks/smarttime",
|
||||||
"version": "3.0.0",
|
"version": "3.0.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarttime",
|
"name": "@pushrocks/smarttime",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.0.0",
|
"version": "3.0.2",
|
||||||
"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",
|
||||||
|
14
readme.md
14
readme.md
@ -1,4 +1,4 @@
|
|||||||
# smarttime
|
# @pushrocks/smarttime
|
||||||
|
|
||||||
handle timeformats in smart ways
|
handle timeformats in smart ways
|
||||||
|
|
||||||
@ -19,12 +19,22 @@ 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.
|
||||||
|
|
||||||
|
### class ExtendedDate
|
||||||
|
|
||||||
|
This class offers static functions to create zone speicific JavaScript dates from European formated time strings.
|
||||||
|
|
||||||
|
```TypeScript
|
||||||
|
import { ExtendedDate } from '@pushrocks/smarttime'
|
||||||
|
const myDate: Date = ExtendedDate.fromEuropeanDate('8.6.2018')
|
||||||
|
```
|
||||||
|
|
||||||
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)
|
||||||
|
@ -3,8 +3,13 @@ import { expect, tap } from '@pushrocks/tapbundle';
|
|||||||
import * as smarttime from '../ts/index';
|
import * as smarttime from '../ts/index';
|
||||||
|
|
||||||
tap.test('should create a valid JavaScript Date from European TimeStamp', async () => {
|
tap.test('should create a valid JavaScript Date from European TimeStamp', async () => {
|
||||||
const extendedDate = smarttime.ExtendedDate.fromEuropeanDate('10.10.2018');
|
const extendedDate = smarttime.ExtendedDate.fromEuropeanDate('1.6.2018');
|
||||||
console.log(extendedDate);
|
console.log(extendedDate);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should create a date and time with European Format', async () => {
|
||||||
|
const extendedDate = smarttime.ExtendedDate.fromEuropeanDateAndTime('9.8.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,27 @@ 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 sliceDate = (dateString: string) => {
|
||||||
|
return `0${dateString}`.slice(-2);
|
||||||
|
};
|
||||||
|
const dateTimeString = `${dateArray[3]}-${sliceDate(dateArray[2])}-${sliceDate(dateArray[1])}T${timeArg}`;
|
||||||
|
const luxonDate = plugins.luxon.DateTime.fromISO(
|
||||||
|
dateTimeString,
|
||||||
|
{
|
||||||
|
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