Compare commits

..

13 Commits

Author SHA1 Message Date
10bff069c1 3.0.4 2018-11-23 18:48:08 +01:00
8f6272eca4 fix(core): update 2018-11-23 18:48:07 +01:00
f02df7789c 3.0.3 2018-11-23 18:29:38 +01:00
d720b8b084 fix(core): update 2018-11-23 18:29:38 +01:00
6bca8557f9 3.0.2 2018-10-21 17:32:03 +02:00
f0a5e18335 fix(ExtendedDate): now respects single digit dates 2018-10-21 17:32:03 +02:00
57fbdb4a70 update 2018-10-21 17:23:58 +02:00
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
f161f71c4e 3.0.0 2018-10-17 01:42:36 +02:00
ed1f79caa4 BREAKING CHANGE(deps): remove moment and use luxon 2018-10-17 01:42:36 +02:00
539bbc1568 2.0.2 2018-07-13 00:03:08 +02:00
7d4bf05289 fix(dependencies): leaner dependencies 2018-07-13 00:03:08 +02:00
13 changed files with 967 additions and 196 deletions

View File

@ -26,6 +26,7 @@ mirror:
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
@ -39,6 +40,7 @@ snyk:
testLEGACY:
stage: test
script:
- npmci npm prepare
- npmci node install legacy
- npmci npm install
- npmci npm test
@ -51,6 +53,7 @@ testLEGACY:
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
@ -62,6 +65,7 @@ testLTS:
testSTABLE:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
@ -117,8 +121,10 @@ pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g npmpage
- npmci command npmpage
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags:
- docker
- notpriv
@ -128,3 +134,4 @@ pages:
expire_in: 1 week
paths:
- public
allow_failure: true

View File

@ -1,8 +1,6 @@
{
"npmci": {
"npmGlobalTools": [
"npmts"
],
"npmGlobalTools": [],
"npmAccessLevel": "public"
}
}

998
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +1,28 @@
{
"name": "@pushrocks/smarttime",
"private": false,
"version": "2.0.1",
"version": "3.0.4",
"description": "handle timeformats in smart ways",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tsrun ./test/test.ts)",
"build": "(npmts)"
"test": "(tstest ./test/)",
"build": "(tsbuild)"
},
"devDependencies": {
"@gitzone/tsrun": "^1.0.5",
"@types/node": "^9.4.7",
"tapbundle": "^2.0.0"
"@gitzone/tsbuild": "^2.0.22",
"@gitzone/tsrun": "^1.1.13",
"@gitzone/tstest": "^1.0.15",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.12.10",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.16.0"
},
"dependencies": {
"moment": "^2.21.0",
"smartdelay": "^1.0.4",
"smartq": "^1.1.6"
"@pushrocks/smartpromise": "^2.0.5",
"@types/luxon": "^1.4.1",
"luxon": "^1.8.0"
}
}

View File

@ -1,4 +1,4 @@
# smarttime
# @pushrocks/smarttime
handle timeformats in smart ways
@ -19,12 +19,22 @@ handle timeformats in smart ways
[![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/)
[![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
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.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)

19
test/test.date.ts Normal file
View File

@ -0,0 +1,19 @@
import { expect, tap } from '@pushrocks/tapbundle';
import * as smarttime from '../ts/index';
tap.test('should create a valid JavaScript Date from European TimeStamp', async () => {
const extendedDate = smarttime.ExtendedDate.fromEuropeanDate('1.6.2018');
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();

View File

@ -1,5 +1,5 @@
// tslint:disable-next-line:no-implicit-dependencies
import { expect, tap } from 'tapbundle';
import { expect, tap } from '@pushrocks/tapbundle';
import { Timer } from '../ts/index';
@ -15,4 +15,12 @@ tap.test('should start timer', async () => {
await testTimer.completed;
});
tap.test('should reset a timer', async () => {
testTimer.reset();
testTimer.start();
testTimer.reset();
testTimer.start();
await testTimer.completed;
});
tap.start();

View File

@ -1,5 +1,5 @@
// tslint:disable-next-line:no-implicit-dependencies
import { expect, tap } from 'tapbundle';
import { expect, tap } from '@pushrocks/tapbundle';
import * as smarttime from '../ts/index';
// Test TimeStamp class

View File

@ -1,8 +1,9 @@
import * as plugins from './smarttime.plugins';
export * from './smarttime.classes.date';
export * from './smarttime.classes.hrtmeasurement';
export * from './smarttime.classes.timer';
export * from './smarttime.classes.timestamp';
export * from './smarttime.units';
export { moment } from './smarttime.plugins';
export { luxon } from './smarttime.plugins';

View File

@ -1 +1,40 @@
import * as plugins from './smarttime.plugins';
export type TAvailableZone = 'Europe/Berlin';
export class ExtendedDate extends Date {
public static fromEuropeanDate(europeanDate: string) {
const dateArray = /(.*)\.(.*)\.(.*)/.exec(europeanDate);
const luxonDate = plugins.luxon.DateTime.utc(
parseFloat(dateArray[3]), // year
parseFloat(dateArray[2]), // month
parseFloat(dateArray[1]) // day
);
const unixMilli = luxonDate.toMillis();
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) {
super(unixMilli);
}
}

View File

@ -39,7 +39,7 @@ export class Timer {
private currentTimeout: NodeJS.Timer;
// a deferred triggeted when Timer has completed
private completedDeferred = plugins.smartq.defer<void>();
private completedDeferred = plugins.smartpromise.defer<void>();
constructor(timeInMillisecondsArg: number) {
this.timeInMilliseconds = timeInMillisecondsArg;
@ -62,6 +62,7 @@ export class Timer {
public pause() {
clearTimeout(this.currentTimeout);
this.currentTimeout = null;
this.pausedAt = TimeStamp.fromTimeStamp(this.startedAt);
}
@ -70,6 +71,14 @@ export class Timer {
this.currentTimeout = setTimeout(() => {
this.completedDeferred.resolve();
}, this.timeLeft);
} else {
throw new Error('timer has NOT been started before. Please use .start() instead');
}
}
public reset() {
this.pause();
this.startedAt = null;
this.pausedAt = null;
}
}

View File

@ -1,4 +1,9 @@
import * as moment from 'moment';
import * as smartq from 'smartq';
// @pushrocks scope
import * as smartpromise from '@pushrocks/smartpromise';
export { moment, smartq };
export { smartpromise };
// third parties
import * as luxon from 'luxon';
export { luxon };

View File

@ -1,6 +1,17 @@
{
"extends": [
"tslint:latest",
"tslint-config-prettier"
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}