Skip to content

Commit

Permalink
time
Browse files Browse the repository at this point in the history
  • Loading branch information
itallonet committed May 30, 2024
1 parent eb62e17 commit 761574e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,23 @@ console.log(celsiusToFahrenheitResult)

```

- Time (ns, mu, ms, s, min, h, d, week, month, year)

``` js

import { Time } from "@itallonet/unit-converter";

const minuteToYearResult = Time(1000, { from: "min", to: "year" });
console.log(minuteToYearResult)

```

## Author

- [@itallonet](https://www.github.com/itallonet)

## Roadmap

- Time
- Frequency
- Speed
- Pressure
Expand Down
12 changes: 12 additions & 0 deletions RESULTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,16 @@ Temperature(1000, { from: "F", to: "K" }) execution time: 0.018ms
Temperature(1000, { from: "K", to: "F" }) execution time: 0.077ms
Temperature(1000, { from: "K", to: "C" }) execution time: 0.015ms

```

# Time Test

```js

Time(1000, { from: "ms", to: "s" }) execution time: 0.072ms
Time(1000, { from: "ms", to: "min" }) execution time: 0.016ms
Time(1000, { from: "ms", to: "h" }) execution time: 0.014ms
Time(1000, { from: "ms", to: "d" }) execution time: 0.031ms
Time(1000, { from: "ms", to: "year" }) execution time: 0.017ms

```
22 changes: 20 additions & 2 deletions __test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Length, Area, Mass, Volume, Temperature } = require("./module")
const { Length, Area, Mass, Volume, Temperature, Time } = require("./module")

const __test = () => {
console.info("Init tests!")
Expand Down Expand Up @@ -121,8 +121,26 @@ const __test = () => {
console.log(`Temperature(1000, { from: "${test.from}", to: "${test.to}" }) = ${result}`);
});

console.info("Time")

tests = [
{ from: "ms", to: "s" },
{ from: "ms", to: "min" },
{ from: "ms", to: "h" },
{ from: "ms", to: "d" },
{ from: "ms", to: "year" },
]

tests.forEach((test) => {
const label = `Time(1000, { from: "${test.from}", to: "${test.to}" }) execution time`;
console.time(label);
const result = Time(1000, test);
console.timeEnd(label);
console.log(`Time(1000, { from: "${test.from}", to: "${test.to}" }) = ${result}`);
});

//todo
// test temperature
// test time
}

__test();
4 changes: 2 additions & 2 deletions module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Length = require("./source/length"), Area = require("./source/area"),
Mass = require("./source/mass"), Volume = require("./source/volume"),
Temperature = require("./source/temperature");
Temperature = require("./source/temperature"), Time = require("./source/time");

module.exports = { Length, Area, Mass, Volume, Temperature }
module.exports = { Length, Area, Mass, Volume, Temperature, Time }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itallonet/unit-converter",
"version": "0.5.0",
"version": "0.6.0",
"description": "Simple and easy to use unit converter for javascript in general",
"main": "module.js",
"scripts": {
Expand Down
20 changes: 20 additions & 0 deletions source/time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const Converter = require("./converter");

function Time(input, options) {
const conversionFactors = {
ns: 1,
mu: 1000,
ms: 1000000,
s: 1000000000,
min: 60000000000,
h: 3600000000000,
d: 86400000000000,
week: 604800000000000,
month: 2.628e+15,
year: 3.154e+16
}

return Converter(input, options, conversionFactors);
}

module.exports = Time;

0 comments on commit 761574e

Please sign in to comment.