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

Commit d151802

Browse files
author
Jonas Schubert
committed
Merge branch 'develop'
2 parents 5c1bd03 + 1529850 commit d151802

File tree

6 files changed

+57
-14
lines changed

6 files changed

+57
-14
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# TimeXt-JavaScript - master branch
22

3-
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4-
<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>
5-
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/)
3+
[![Npm](https://img.shields.io/badge/npm-getit-red.svg)](https://www.npmjs.com/package/timext-js)
4+
[![Build](https://img.shields.io/badge/build-success-green.svg)](https://github.com/TimeXt/TimeXt-JavaScript/blob/master/releases/timext-2018-10-28-2.min.js)
5+
[![Version](https://img.shields.io/badge/version-v0.4.0.181028-blue.svg)](https://github.com/TimeXt/TimeXt-JavaScript/releases)
86
[![CodeCoverage](https://img.shields.io/badge/codeCoverage-98-green.svg)](https://github.com/TimeXt/TimeXt-JavaScript/tree/master/coverage/)
97

10-
[![Npm](https://img.shields.io/badge/npm-getit-red.svg)](https://www.npmjs.com/package/timext-js)
8+
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
9+
<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>
1110

1211
First of all many thanks to [Kizitonwose](https://github.com/kizitonwose/Time) for the original idea and already awesome library!
1312

14-
This minimized ( < 2kB) library shall help to reduce code like
13+
This minimized ( < 3kB) library shall help to reduce code like
1514

1615
```javascript
1716
const dayInMillis = 24 * 60 * 60 * 1000; // Represent a day in milliSeconds
@@ -60,9 +59,13 @@ const sixMinutes = Number(6).toMinutes(); // returns timext(6,
6059
const fiftySeconds = Number(50).toSeconds(); // returns timext(50, u.S)
6160
const hundredMilliseconds = Number(100).toMilliseconds(); // returns timext(100, u.MS)
6261

62+
// Return in other time units
63+
const oneDayInMillis = Number(1).toDays().inMilliseconds();// Returns one day in milliseconds === 24 * 60 * 60 * 1e3
64+
const twoWeeksInHours = Number(2).toWeeks().inHours(); // Returns two weeks in hours === 2 * 7 * 24
65+
6366
// 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
67+
const oneDayInMillis = Number(1).toDays().toHours(); // Converts one day into timext(24, u.H)
68+
const twoWeeksInHours = Number(120).toMinutes().toHours(); // Converts 120 hours into timext(2, u.H)
6669

6770
// add timext to date using date extensions
6871
const inFiveDays = Date.now.plus(Number(5).toDays());

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "timext-js",
3-
"version": "0.3.0",
4-
"description": "2kB time library to handle date and time more easily",
3+
"version": "0.4.0",
4+
"description": "3kB time library to handle date and time more easily",
55
"main": "timext.min.js",
66
"types": "",
77
"scripts": {
@@ -28,7 +28,7 @@
2828
],
2929
"size-limit": [
3030
{
31-
"limit": "2.00 KB",
31+
"limit": "3.00 KB",
3232
"path": "timext.min.js"
3333
}
3434
],

releases/timext-2018-10-28-2.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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,34 @@ class TimeXt {
3535
return (this.val * this.unit) / u.MS;
3636
}
3737

38+
toYears() {
39+
return new TimeXt(this.inYears(), u.Y);
40+
}
41+
42+
toWeeks() {
43+
return new TimeXt(this.inWeeks(), u.W);
44+
}
45+
46+
toDays() {
47+
return new TimeXt(this.inDays(), u.D);
48+
}
49+
50+
toHours() {
51+
return new TimeXt(this.inHours(), u.H);
52+
}
53+
54+
toMinutes() {
55+
return new TimeXt(this.inMinutes(), u.M);
56+
}
57+
58+
toSeconds() {
59+
return new TimeXt(this.inSeconds(), u.S);
60+
}
61+
62+
toMilliseconds() {
63+
return new TimeXt(this.inMilliseconds(), u.MS);
64+
}
65+
3866
plus(t) {
3967
this.val = ((this.inMilliseconds() + t.inMilliseconds()) / this.unit) * u.MS;
4068
return this;

test/index.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import timext from '../src/index';
22
import * as u from '../src/units';
33

4-
it('All conversions should work as expected', () => {
4+
it('All in conversions should work as expected', () => {
55
expect(Math.round(timext(730, u.D).inYears())).toBe(2);
66
expect(Math.round(timext(21, u.D).inWeeks())).toBe(3);
77
expect(Math.round(timext(1, u.Y).inDays())).toBe(365);
@@ -12,6 +12,17 @@ it('All conversions should work as expected', () => {
1212
expect(Math.round(timext(2, u.S).inMilliseconds())).toBe(2000);
1313
})
1414

15+
it('All to conversions should work as expected', () => {
16+
expect(timext(730, u.D).toYears()).toEqual(timext(2, u.Y));
17+
expect(timext(21, u.D).toWeeks()).toEqual(timext(3, u.W));
18+
expect(timext(1, u.Y).toDays()).toEqual(timext(365, u.D));
19+
expect(timext(2, u.W).toDays()).toEqual(timext(14, u.D));
20+
expect(timext(2, u.D).toHours()).toEqual(timext(48, u.H));
21+
expect(timext(2, u.H).toMinutes()).toEqual(timext(120, u.M));
22+
expect(timext(2, u.M).toSeconds()).toEqual(timext(120, u.S));
23+
expect(timext(2, u.S).toMilliseconds()).toEqual(timext(2000, u.MS));
24+
})
25+
1526
it('All arithmetic operator should work as expected', () => {
1627
expect(timext(2, u.W).plus(timext(7, u.D))).toEqual(timext(3, u.W));
1728
expect(timext(4, u.H).plus(timext(30, u.M))).toEqual(timext(4.5, u.H));

timext.min.js

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

0 commit comments

Comments
 (0)