Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some issues #2

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ jobs:
with:
version: 3.x
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: baptiste0928/cargo-install@v3
with:
crate: dprint
- uses: oven-sh/setup-bun@v1
- run: bun install --frozon-lockfile
- run: task ci
- run: task check
- run: task test
- run: task build
Expand Down
4 changes: 4 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
tabWidth: 4,
endOfLine: "auto",
};
22 changes: 20 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
version: '3'

tasks:
install:
desc: Install dependencies
cmds:
- bun install

ci:
cmds:
- bun install --frozen-lockfile

test:
desc: Run tests
cmds:
Expand All @@ -15,12 +24,21 @@ tasks:
desc: Check for issues
cmds:
- bunx --bun tsc
- dprint check
- task: prettier
vars:
PRETTIER_ARGS: --check

fix:
desc: Fix issues
cmds:
- dprint fmt
- task: prettier
vars:
PRETTIER_ARGS: --write


prettier:
cmds:
- bunx --bun prettier "./**/*.{html,ts,tsx,json,js,jsx,cjs,css}" {{.PRETTIER_ARGS}}

build:
desc: Build the distributable web app
Expand Down
Binary file modified bun.lockb
Binary file not shown.
19 changes: 0 additions & 19 deletions dprint.json

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "addtime",
"devDependencies": {
"@types/bun": "latest",
"prettier": "^3.2.5",
"serve": "^14.2.3",
"typescript": "^5.0.0"
}
Expand Down
125 changes: 85 additions & 40 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,47 +1,92 @@
<!doctype html>
<!-- https://www.sitepoint.com/a-basic-html5-template/ -->
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<title>Adder of Time</title>
<meta property="og:site_name" content="Pistonite"/>
<meta property="og:title" content="Adder of Time">
<meta property="og:type" content="website">
<meta property="og:url" content="https://pistonite.github.io/addtime">
<meta property="og:description" content="A simple but correct time adder">
</head>
<title>Adder of Time</title>
<meta property="og:site_name" content="Pistonite" />
<meta property="og:title" content="Adder of Time" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://pistonite.github.io/addtime" />
<meta
property="og:description"
content="A simple but correct time adder"
/>
</head>

<body>
<h1>Adder of Time</h1>
<label for="help">Reference</label>
<p>d - days, h - hours, m - minutes, s - seconds, (no unit) - milliseconds</p>
<body>
<h1>Adder of Time</h1>
<label for="help">Reference</label>
<p>
d - days, h - hours, m - minutes, s - seconds, (no unit) -
milliseconds
</p>

<input type="radio" id="radio_unit_1000" name="radio_unit" value="1000" checked onchange="__addtime_update();">
<label for="radio_unit_1000">No Alignment</label><br/>
<input type="radio" id="radio_unit_30" name="radio_unit" value="30" onchange="__addtime_update();">
<label for="radio_unit_30">30 FPS</label><br/>
<input type="radio" id="radio_unit_60" name="radio_unit" value="60" onchange="__addtime_update();">
<label for="radio_unit_60">60 FPS</label><br/>
<label for="input">Input:</label>
<br/>
<textarea id="input" rows="5" cols="50" placeholder="1m20s + 5m30s - 1m39s " oninput="__addtime_update();"></textarea>
<br/>
<label for="output">Output:</label>
<br/>
<textarea id="output" rows="5" cols="50" placeholder="(Output will be shown as you type in input)" readonly></textarea>
<br/>
<label for="error">Errors:</label>
<br/>
<textarea id="error" rows="5" cols="50" placeholder="(No Error :)" readonly></textarea>
<br/>
<p>
Source on <a href="https://github.com/Pistonite/addtime">GitHub</a>. Report bugs there too
</p>
<p>
You can use this app with Google Sheet! Check out the GitHub link above for more info.
</p>
<script src="main.js"></script>
</body>
<input
type="radio"
id="radio_unit_1000"
name="radio_unit"
value="1000"
checked
onchange="__addtime_update();"
/>
<label for="radio_unit_1000">No Alignment</label><br />
<input
type="radio"
id="radio_unit_30"
name="radio_unit"
value="30"
onchange="__addtime_update();"
/>
<label for="radio_unit_30">30 FPS</label><br />
<input
type="radio"
id="radio_unit_60"
name="radio_unit"
value="60"
onchange="__addtime_update();"
/>
<label for="radio_unit_60">60 FPS</label><br />
<label for="input">Input:</label>
<br />
<textarea
id="input"
rows="5"
cols="50"
placeholder="1m20s + 5m30s - 1m39s "
oninput="__addtime_update();"
></textarea>
<br />
<label for="output">Output:</label>
<br />
<textarea
id="output"
rows="5"
cols="50"
placeholder="(Output will be shown as you type in input)"
readonly
></textarea>
<br />
<label for="error">Errors:</label>
<br />
<textarea
id="error"
rows="5"
cols="50"
placeholder="(No Error :)"
readonly
></textarea>
<br />
<p>
Source on <a href="https://github.com/Pistonite/addtime">GitHub</a>.
Report bugs there too
</p>
<p>
You can use this app with Google Sheet! Check out the GitHub link
above for more info.
</p>
<script src="main.js"></script>
</body>
</html>
14 changes: 10 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import { calc } from "./time";
function update() {
const input = (document.getElementById("input") as HTMLInputElement).value;
var unit = BigInt(1000);
if ((document.getElementById("radio_unit_30") as HTMLInputElement).checked) {
if (
(document.getElementById("radio_unit_30") as HTMLInputElement).checked
) {
unit = BigInt(30);
} else if ((document.getElementById("radio_unit_60") as HTMLInputElement).checked) {
} else if (
(document.getElementById("radio_unit_60") as HTMLInputElement).checked
) {
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");
(document.getElementById("output") as HTMLTextAreaElement).value =
answers.join(",\n");
(document.getElementById("error") as HTMLTextAreaElement).value =
errors.join(",\n");
}

(window as any).__addtime_update = update;
21 changes: 18 additions & 3 deletions src/time.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { describe, expect, test } from "bun:test";
import { makeMs, makeQuantum, tokenize, toMilliseconds, toQuantum } from "./time.ts";
import {
makeMs,
makeQuantum,
tokenize,
toMilliseconds,
toQuantum,
} from "./time.ts";

test("should convert between 30fps and milliseconds", () => {
let frame = BigInt(0);
const adds = [BigInt(33), BigInt(34), BigInt(33)];
for (let ms = BigInt(0); ms < BigInt(1000);) {
for (let ms = BigInt(0); ms < BigInt(1000); ) {
for (let i = 0; i < adds.length; i++) {
const msValue = makeMs(ms);
const frameValue = makeQuantum(frame, BigInt(30));
Expand All @@ -25,7 +31,16 @@ describe("tokenize", () => {
expect(tokenize("30h")).toEqual(["30", "h"]);
});
test("expression", () => {
expect(tokenize("30h 12m + 2s300")).toEqual(["30", "h", "12", "m", "+", "2", "s", "300"]);
expect(tokenize("30h 12m + 2s300")).toEqual([
"30",
"h",
"12",
"m",
"+",
"2",
"s",
"300",
]);
});
test("multiple expressions", () => {
expect(tokenize("30h- 12m+ 2s300, asdfasdf")).toEqual([
Expand Down
Loading