Skip to content
This repository was archived by the owner on Jan 22, 2023. It is now read-only.

Commit 5c1bd03

Browse files
author
Jonas Schubert
committed
Merge branch 'develop'
2 parents 2966379 + 521e438 commit 5c1bd03

12 files changed

+42
-80
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ coverage
1919
#dev
2020
demo.js
2121

22+
#folder
2223
.vs

.npmignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ docs
2525

2626
#other
2727
.travis.yml
28-
karma.sauce.conf.js
28+
karma.sauce.conf.js
29+
30+
#folder
31+
.vs

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
44
<a target="_blank" href="https://www.paypal.me/GuepardoApps" title="Donate using PayPal"><img src="https://img.shields.io/badge/paypal-donate-blue.svg" /></a>
55

6-
[![Build](https://img.shields.io/badge/build-success-green.svg)](https://github.com/TimeXt/TimeXt-JavaScript/blob/master/releases/timext-2018-10-27-2.min.js)
7-
[![Version](https://img.shields.io/badge/version-v0.2.2.181027-blue.svg)](https://github.com/TimeXt/TimeXt-JavaScript/tree/master/releases/)
8-
[![CodeCoverage](https://img.shields.io/badge/codeCoverage-98-green.svg)](https://github.com/TimeXt/TimeXt-JavaScript/tree/master/test/)
6+
[![Build](https://img.shields.io/badge/build-success-green.svg)](https://github.com/TimeXt/TimeXt-JavaScript/blob/master/releases/timext-2018-10-28-1.min.js)
7+
[![Version](https://img.shields.io/badge/version-v0.3.0.181028-blue.svg)](https://github.com/TimeXt/TimeXt-JavaScript/tree/master/releases/)
8+
[![CodeCoverage](https://img.shields.io/badge/codeCoverage-98-green.svg)](https://github.com/TimeXt/TimeXt-JavaScript/tree/master/coverage/)
99

1010
[![Npm](https://img.shields.io/badge/npm-getit-red.svg)](https://www.npmjs.com/package/timext-js)
1111

@@ -26,6 +26,7 @@ import timext from '../src/index';
2626
import * as u from '../src/units';
2727

2828
// Create by using constructor method
29+
const twoYears = timext(2, u.Y);
2930
const oneWeek = timext(1, u.W);
3031
const threeDays = timext(3, u.D);
3132
const elevenHours = timext(11, u.H);
@@ -51,13 +52,18 @@ If you want to use the minified script from the releases
5152
import 'timext.min';
5253

5354
// Create by using number extensions
55+
const twoYears = Number(2).toYears(); // returns timext(2, u.Y)
5456
const oneWeek = Number(1).toWeeks(); // returns timext(1, u.W)
5557
const threeDays = Number(3).toDays(); // returns timext(3, u.D)
5658
const elevenHours = Number(11).toHours(); // returns timext(11, u.H)
5759
const sixMinutes = Number(6).toMinutes(); // returns timext(6, u.M)
5860
const fiftySeconds = Number(50).toSeconds(); // returns timext(50, u.S)
5961
const hundredMilliseconds = Number(100).toMilliseconds(); // returns timext(100, u.MS)
6062

63+
// Convert to other time units
64+
const oneDayInMillis = Number(1).toDays().inMilliseconds();// Converts one day into milliseconds === 24 * 60 * 60 * 1e3
65+
const twoWeeksInHours = Number(2).toWeeks().inHours(); // Converts two weeks into hours === 2 * 7 * 24
66+
6167
// add timext to date using date extensions
6268
const inFiveDays = Date.now.plus(Number(5).toDays());
6369
const threeWeeksAgo = Date.now.minus(Number(3).toWeeks());

package.json

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"name": "timext-js",
3-
"version": "0.2.2",
4-
"description": "",
3+
"version": "0.3.0",
4+
"description": "2kB time library to handle date and time more easily",
55
"main": "timext.min.js",
66
"types": "",
77
"scripts": {
88
"test": "jest",
99
"lint": "./node_modules/.bin/eslint src/* test/* build/*",
1010
"build": "cross-env BABEL_ENV=build node build",
1111
"sauce": "npx karma start karma.sauce.conf.js",
12-
"test:sauce": "npm run sauce -- 0 && npm run sauce -- 1 && npm run sauce -- 2 && npm run sauce -- 3"
12+
"test:sauce": "npm run sauce -- 0 && npm run sauce -- 1 && npm run sauce -- 2 && npm run sauce -- 3",
13+
"size": "size-limit && gzip-size timext.min.js"
1314
},
1415
"repository": {
1516
"type": "git",
@@ -25,6 +26,12 @@
2526
"pre-commit": [
2627
"lint"
2728
],
29+
"size-limit": [
30+
{
31+
"limit": "2.00 KB",
32+
"path": "timext.min.js"
33+
}
34+
],
2835
"jest": {
2936
"roots": [
3037
"test"
@@ -57,7 +64,7 @@
5764
"eslint": "^4.19.1",
5865
"eslint-config-airbnb-base": "^12.1.0",
5966
"eslint-plugin-import": "^2.10.0",
60-
"eslint-plugin-jest": "^21.15.0",
67+
"eslint-plugin-jest": "^21.26.2",
6168
"gzip-size-cli": "^2.1.0",
6269
"jasmine-core": "^2.99.1",
6370
"jest": "^22.4.3",
@@ -67,7 +74,9 @@
6774
"pre-commit": "^1.2.2",
6875
"rollup": "^0.57.1",
6976
"rollup-plugin-babel": "^4.0.0-beta.4",
70-
"rollup-plugin-uglify": "^3.0.0"
77+
"rollup-plugin-uglify": "^3.0.0",
78+
"size-limit": "^0.18.0",
79+
"typescript": "^2.8.3"
7180
},
7281
"dependencies": {}
7382
}

releases/timext-2018-10-28-1.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ class TimeXt {
77
this.unit = unit;
88
}
99

10+
inYears() {
11+
return (this.val * this.unit) / u.Y;
12+
}
13+
1014
inWeeks() {
1115
return (this.val * this.unit) / u.W;
1216
}
@@ -98,6 +102,10 @@ Date.prototype.minus = function (val) {
98102

99103
// Number extensions
100104

105+
Number.prototype.toYears = function () {
106+
return timext(this, u.Y);
107+
}
108+
101109
Number.prototype.toWeeks = function () {
102110
return timext(this, u.W);
103111
}

src/number.extensions.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/units.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export const Y = 365 * 24 * 60 * 60 * 1e3;
12
export const W = 7 * 24 * 60 * 60 * 1e3;
23
export const D = 24 * 60 * 60 * 1e3;
34
export const H = 60 * 60 * 1e3;

test/index.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import timext from '../src/index';
22
import * as u from '../src/units';
33

44
it('All conversions should work as expected', () => {
5+
expect(Math.round(timext(730, u.D).inYears())).toBe(2);
56
expect(Math.round(timext(21, u.D).inWeeks())).toBe(3);
7+
expect(Math.round(timext(1, u.Y).inDays())).toBe(365);
68
expect(Math.round(timext(2, u.W).inDays())).toBe(14);
79
expect(Math.round(timext(2, u.D).inHours())).toBe(48);
810
expect(Math.round(timext(2, u.H).inMinutes())).toBe(120);

test/interval.test.js

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)