Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
f02df7789c | |||
d720b8b084 | |||
6bca8557f9 | |||
f0a5e18335 | |||
57fbdb4a70 | |||
4a56527f7d | |||
2a14d928a8 |
@ -135,13 +135,3 @@ pages:
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
||||
windowsCompatibility:
|
||||
image: stefanscherer/node-windows:10-build-tools
|
||||
stage: metadata
|
||||
script:
|
||||
- npm install & npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- windows
|
||||
allow_failure: true
|
||||
|
26
package-lock.json
generated
26
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smarttime",
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -251,14 +251,14 @@
|
||||
}
|
||||
},
|
||||
"@types/luxon": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-1.4.0.tgz",
|
||||
"integrity": "sha512-jECW+lbzPICLGqN/dBdX6Lwn5s84okwM2EVjcYim7hkh5+Ebej8kjxY7InBlsORNjGe8v7lPpd/88a0qkoEcuA=="
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-1.4.1.tgz",
|
||||
"integrity": "sha512-mYv/gbkOJ40CDgR8st5sosfFNrJncdlkpdzQSNRdU86UQg3oWWmll4AO/7B8F5FlBC6YrIXqXDSnkoCBqo+uMA=="
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "10.12.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.0.tgz",
|
||||
"integrity": "sha512-3TUHC3jsBAB7qVRGxT6lWyYo2v96BMmD2PTcl47H25Lu7UXtFH/2qqmKiVrnel6Ne//0TFYf6uvNX+HW2FRkLQ==",
|
||||
"version": "10.12.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.10.tgz",
|
||||
"integrity": "sha512-8xZEYckCbUVgK8Eg7lf5Iy4COKJ5uXlnIOnePN0WUwSQggy9tolM+tDJf7wMOnT/JT/W9xDYIaYggt3mRV2O5w==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/vinyl": {
|
||||
@ -718,9 +718,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"luxon": {
|
||||
"version": "1.4.3",
|
||||
"resolved": "https://registry.npmjs.org/luxon/-/luxon-1.4.3.tgz",
|
||||
"integrity": "sha512-hujVJ+Q2RnaIiHKAupwusgpHXYICxzXJNoPkqkGIfmP+lLZWFTD6gEP+URRs/vh5gI1KwfMimVrzM9309RE0tA=="
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/luxon/-/luxon-1.8.0.tgz",
|
||||
"integrity": "sha512-F742cYUYB7X+LXY3cIn6THZUBqRBjeAvF+CWE2i3+eKcv2bzsCsnRsBYL8Qrqzp1dfs6HsVcSjfKt2RcrtUElw=="
|
||||
},
|
||||
"make-error": {
|
||||
"version": "1.3.4",
|
||||
@ -1005,9 +1005,9 @@
|
||||
}
|
||||
},
|
||||
"tslint-config-prettier": {
|
||||
"version": "1.15.0",
|
||||
"resolved": "https://registry.npmjs.org/tslint-config-prettier/-/tslint-config-prettier-1.15.0.tgz",
|
||||
"integrity": "sha512-06CgrHJxJmNYVgsmeMoa1KXzQRoOdvfkqnJth6XUkNeOz707qxN0WfxfhYwhL5kXHHbYJRby2bqAPKwThlZPhw==",
|
||||
"version": "1.16.0",
|
||||
"resolved": "https://registry.npmjs.org/tslint-config-prettier/-/tslint-config-prettier-1.16.0.tgz",
|
||||
"integrity": "sha512-zu6RAcpBtqdvhT6KpBh9kRPYATjOf9BnRi718kNqVKFjEgSE4rFrPprFju1YJrkOa3RbtbWI1ZSuLd2NBX1MDw==",
|
||||
"dev": true
|
||||
},
|
||||
"tsutils": {
|
||||
|
10
package.json
10
package.json
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@pushrocks/smarttime",
|
||||
"private": false,
|
||||
"version": "3.0.0",
|
||||
"version": "3.0.3",
|
||||
"description": "handle timeformats in smart ways",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
@ -16,13 +16,13 @@
|
||||
"@gitzone/tsrun": "^1.1.13",
|
||||
"@gitzone/tstest": "^1.0.15",
|
||||
"@pushrocks/tapbundle": "^3.0.7",
|
||||
"@types/node": "^10.12.0",
|
||||
"@types/node": "^10.12.10",
|
||||
"tslint": "^5.11.0",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
"tslint-config-prettier": "^1.16.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartpromise": "^2.0.5",
|
||||
"@types/luxon": "^1.4.0",
|
||||
"luxon": "^1.4.3"
|
||||
"@types/luxon": "^1.4.1",
|
||||
"luxon": "^1.8.0"
|
||||
}
|
||||
}
|
||||
|
14
readme.md
14
readme.md
@ -1,4 +1,4 @@
|
||||
# smarttime
|
||||
# @pushrocks/smarttime
|
||||
|
||||
handle timeformats in smart ways
|
||||
|
||||
@ -19,12 +19,22 @@ handle timeformats in smart ways
|
||||
[](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/)
|
||||
[](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)
|
||||
|
@ -3,7 +3,16 @@ 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('10.10.2018');
|
||||
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);
|
||||
});
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
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);
|
||||
@ -12,6 +14,26 @@ export class ExtendedDate extends Date {
|
||||
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);
|
||||
}
|
||||
|
@ -70,6 +70,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;
|
||||
}
|
||||
}
|
||||
|
19
tslint.json
19
tslint.json
@ -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"
|
||||
}
|
||||
|
Reference in New Issue
Block a user