Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
f02df7789c | |||
d720b8b084 | |||
6bca8557f9 | |||
f0a5e18335 | |||
57fbdb4a70 | |||
4a56527f7d | |||
2a14d928a8 | |||
f161f71c4e | |||
ed1f79caa4 | |||
539bbc1568 | |||
7d4bf05289 |
@ -26,6 +26,7 @@ mirror:
|
|||||||
snyk:
|
snyk:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci command npm install -g snyk
|
- npmci command npm install -g snyk
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command snyk test
|
||||||
@ -39,6 +40,7 @@ snyk:
|
|||||||
testLEGACY:
|
testLEGACY:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install legacy
|
- npmci node install legacy
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -51,6 +53,7 @@ testLEGACY:
|
|||||||
testLTS:
|
testLTS:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install lts
|
- npmci node install lts
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -62,6 +65,7 @@ testLTS:
|
|||||||
testSTABLE:
|
testSTABLE:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
@ -117,8 +121,10 @@ pages:
|
|||||||
image: hosttoday/ht-docker-node:npmci
|
image: hosttoday/ht-docker-node:npmci
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g npmpage
|
- npmci command npm install -g typedoc typescript
|
||||||
- npmci command npmpage
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
@ -128,3 +134,4 @@ pages:
|
|||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
|
||||||
],
|
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
998
package-lock.json
generated
998
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -1,24 +1,28 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smarttime",
|
"name": "@pushrocks/smarttime",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "2.0.1",
|
"version": "3.0.3",
|
||||||
"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",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tsrun ./test/test.ts)",
|
"test": "(tstest ./test/)",
|
||||||
"build": "(npmts)"
|
"build": "(tsbuild)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsrun": "^1.0.5",
|
"@gitzone/tsbuild": "^2.0.22",
|
||||||
"@types/node": "^9.4.7",
|
"@gitzone/tsrun": "^1.1.13",
|
||||||
"tapbundle": "^2.0.0"
|
"@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": {
|
"dependencies": {
|
||||||
"moment": "^2.21.0",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"smartdelay": "^1.0.4",
|
"@types/luxon": "^1.4.1",
|
||||||
"smartq": "^1.1.6"
|
"luxon": "^1.8.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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)
|
||||||
|
19
test/test.date.ts
Normal file
19
test/test.date.ts
Normal 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();
|
@ -1,5 +1,5 @@
|
|||||||
// tslint:disable-next-line:no-implicit-dependencies
|
// tslint:disable-next-line:no-implicit-dependencies
|
||||||
import { expect, tap } from 'tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
|
|
||||||
import { Timer } from '../ts/index';
|
import { Timer } from '../ts/index';
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// tslint:disable-next-line:no-implicit-dependencies
|
// tslint:disable-next-line:no-implicit-dependencies
|
||||||
import { expect, tap } from 'tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smarttime from '../ts/index';
|
import * as smarttime from '../ts/index';
|
||||||
|
|
||||||
// Test TimeStamp class
|
// Test TimeStamp class
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
import * as plugins from './smarttime.plugins';
|
||||||
|
|
||||||
|
export * from './smarttime.classes.date';
|
||||||
export * from './smarttime.classes.hrtmeasurement';
|
export * from './smarttime.classes.hrtmeasurement';
|
||||||
export * from './smarttime.classes.timer';
|
export * from './smarttime.classes.timer';
|
||||||
export * from './smarttime.classes.timestamp';
|
export * from './smarttime.classes.timestamp';
|
||||||
export * from './smarttime.units';
|
export * from './smarttime.units';
|
||||||
|
|
||||||
export { moment } from './smarttime.plugins';
|
export { luxon } from './smarttime.plugins';
|
||||||
|
@ -1 +1,40 @@
|
|||||||
import * as plugins from './smarttime.plugins';
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -39,7 +39,7 @@ export class Timer {
|
|||||||
private currentTimeout: NodeJS.Timer;
|
private currentTimeout: NodeJS.Timer;
|
||||||
|
|
||||||
// a deferred triggeted when Timer has completed
|
// a deferred triggeted when Timer has completed
|
||||||
private completedDeferred = plugins.smartq.defer<void>();
|
private completedDeferred = plugins.smartpromise.defer<void>();
|
||||||
|
|
||||||
constructor(timeInMillisecondsArg: number) {
|
constructor(timeInMillisecondsArg: number) {
|
||||||
this.timeInMilliseconds = timeInMillisecondsArg;
|
this.timeInMilliseconds = timeInMillisecondsArg;
|
||||||
@ -70,6 +70,14 @@ export class Timer {
|
|||||||
this.currentTimeout = setTimeout(() => {
|
this.currentTimeout = setTimeout(() => {
|
||||||
this.completedDeferred.resolve();
|
this.completedDeferred.resolve();
|
||||||
}, this.timeLeft);
|
}, 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
import * as moment from 'moment';
|
// @pushrocks scope
|
||||||
import * as smartq from 'smartq';
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
|
||||||
export { moment, smartq };
|
export { smartpromise };
|
||||||
|
|
||||||
|
// third parties
|
||||||
|
import * as luxon from 'luxon';
|
||||||
|
|
||||||
|
export { luxon };
|
||||||
|
19
tslint.json
19
tslint.json
@ -1,6 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": [
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
"tslint:latest",
|
"rules": {
|
||||||
"tslint-config-prettier"
|
"semicolon": [true, "always"],
|
||||||
]
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user