-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8be188f
commit ef243ef
Showing
14 changed files
with
214 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Michael | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,22 @@ | ||
# addtime | ||
Adder of Time https://pistonite.github.io/addtime | ||
Adder of Time https://addtime.pistonite.dev | ||
|
||
|
||
## To use in Google Sheet Apps Script | ||
In your Google Sheet, go to `Extensions > Apps Script`, and paste | ||
in [this script](https://pistonite.github.io/addtime/appscript.txt) | ||
in [this script](https://addtime.pistonite.dev/appscript.txt) | ||
|
||
You will have access to the `ADDTIME` function which adds a range of cells, | ||
and the `SUBTIME` function that subtracts 2 cells | ||
The following functions are available: | ||
- `ADDTIME` - Adds a range of cells of time expressions | ||
- `SUBTIME` - Subtracts 2 cells of time expressions | ||
- `DIVTIME` - Divides 2 cells of time expressions | ||
|
||
## To consume as TypeScript library | ||
Download the source to your project | ||
Simply copy the TS source to your project | ||
``` | ||
curl https://pistonite.github.io/addtime/time.ts > somewhere/addtime.ts | ||
curl https://pistonite.github.io/addtime/dist.ts > somewhere/addtime.ts | ||
``` | ||
Then map the path in your `tsconfig.json` | ||
```json | ||
{ | ||
"compilerOptions": { | ||
"paths": { | ||
"addtime": ["base/rel/path/to/somewhere/addtime.ts"] | ||
} | ||
}, | ||
"include": ["path/to/somewhere"] | ||
} | ||
``` | ||
Finally import and use | ||
Then import and use | ||
```typescript | ||
import { calc } from "addtime"; | ||
import { calc, ratio } from "addtime.ts"; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// E2E testing for app script | ||
|
||
function testEq(a, b) { | ||
if (a !== b) { | ||
throw new Error(`Expected ${a} to equal ${b}`); | ||
} | ||
} | ||
|
||
testEq(ADDTIME([["1m20s", "2m40s"]]), "04m00s"); | ||
testEq(SUBTIME("1m20s", "30s"), "50s"); | ||
testEq(DIVTIME("1m", "01m20s"), 0.75); | ||
|
||
console.log("All tests passed!"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { calc } from "./time.ts"; | ||
import { calc, ratio } from "./time.ts"; | ||
|
||
// @ts-ignore | ||
window.__calc = calc; | ||
window.__export = { calc, ratio }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,47 @@ | ||
import { calc } from "./time"; | ||
import { calc, ratio } from "./time"; | ||
|
||
function isChecked(id: string) { | ||
return (document.getElementById(id) as HTMLInputElement).checked; | ||
} | ||
|
||
function valueOf(id: string) { | ||
return (document.getElementById(id) as HTMLInputElement).value; | ||
} | ||
|
||
function setTextArea(id: string, value: string) { | ||
(document.getElementById(id) as HTMLTextAreaElement).value = value; | ||
} | ||
|
||
/// Update the output and errors | ||
function update() { | ||
const input = (document.getElementById("input") as HTMLInputElement).value; | ||
const ratioMode = isChecked("ratio_mode_checkbox"); | ||
const input = valueOf("input"); | ||
|
||
var unit = BigInt(1000); | ||
if ( | ||
(document.getElementById("radio_unit_30") as HTMLInputElement).checked | ||
) { | ||
if (isChecked("radio_unit_30")) { | ||
unit = BigInt(30); | ||
} else if ( | ||
(document.getElementById("radio_unit_60") as HTMLInputElement).checked | ||
) { | ||
} else if (isChecked("radio_unit_60")) { | ||
unit = BigInt(60); | ||
} | ||
const { answers, errors } = calc(input, unit); | ||
(document.getElementById("output") as HTMLTextAreaElement).value = | ||
answers.join(",\n"); | ||
(document.getElementById("error") as HTMLTextAreaElement).value = | ||
errors.join(",\n"); | ||
|
||
if (ratioMode) { | ||
const [a, b] = input.split("\n"); | ||
if (!a || !b) { | ||
setTextArea("error", "Ratio mode requires two lines in input"); | ||
} | ||
const answer = ratio(a, b, unit); | ||
if (typeof answer === "string") { | ||
setTextArea("error", answer); | ||
setTextArea("output", "There is an error"); | ||
} else { | ||
setTextArea("output", answer * 100 + "%"); | ||
setTextArea("error", ""); | ||
} | ||
} else { | ||
const { answers, errors } = calc(input, unit); | ||
setTextArea("output", answers.join(",\n")); | ||
setTextArea("error", errors.join(",\n")); | ||
} | ||
} | ||
|
||
(window as any).__addtime_update = update; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.