Skip to content
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
4 changes: 2 additions & 2 deletions src/game.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formatCount } from "./util";
import { formatANoun, formatCount } from "./util";

export const BASE_RATING = 1200;
export const SCALING_FACTOR = 800;
Expand Down Expand Up @@ -139,7 +139,7 @@ export function addCard(deck, card, gameMode, findState) {
}
const set = setTypes[setType].checkFn(...cards);
if (!set) {
return { kind: "error", cards, error: `Not a ${setType}` };
return { kind: "error", cards, error: `Not ${formatANoun(setType)}` };
}
if (modes[gameMode].puzzle && foundSets.has(set.slice().sort().join("|"))) {
return { kind: "error", cards, error: `This ${setType} was already found` };
Expand Down
5 changes: 3 additions & 2 deletions src/pages/BannedPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import Container from "@material-ui/core/Container";
import Link from "@material-ui/core/Link";
import Typography from "@material-ui/core/Typography";

import { formatDateTime } from "../util";

function BannedPage({ time }) {
const date = new Date(time);
return (
<Container style={{ padding: 16 }}>
<Typography variant="h4" align="center" gutterBottom>
Banned
</Typography>
<Typography variant="body1" align="center" gutterBottom>
Due to a violation of the site's code of conduct,{" "}
<strong>you have been banned until {date.toLocaleString()}</strong>.
<strong>you have been banned until {formatDateTime(time)}</strong>.
</Typography>
<Typography variant="body1" align="center" gutterBottom>
Please take some time to cool off. If you have questions about this,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/GamePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from "../game";
import useFirebaseRef from "../hooks/useFirebaseRef";
import useKeydown, { getModifierState } from "../hooks/useKeydown";
import { formatANoun } from "../util";
import LoadingPage from "./LoadingPage";
import NotFoundPage from "./NotFoundPage";

Expand Down Expand Up @@ -288,7 +289,7 @@ function GamePage({ match }) {
setSnack({
open: true,
variant: "success",
message: `Found a ${state.setType}`,
message: `Found ${formatANoun(state.setType)}`,
});
}
return [];
Expand Down
9 changes: 7 additions & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ export function formatCount(count, singular, plural = null) {
return `${count} ${noun}`;
}

export function formatANoun(word) {
const a = /^[aeiou]/i.test(word) ? "an" : "a"; // crud heuristic
return `${a} ${word}`;
}

export function censorText(text) {
return censor.applyTo(text, badWords.getAllMatches(text));
}
Expand All @@ -153,8 +158,8 @@ export function capitalizeFirst(text) {

export function formatDateTime(timestamp) {
const d = new Date(timestamp);
const opts = { timeStyle: "short", hour12: false };
return `${d.toLocaleDateString()} ${d.toLocaleTimeString(undefined, opts)}`;
const opts = { dateStyle: "medium", timeStyle: "short", hour12: false };
return d.toLocaleString(undefined, opts);
}

export function parseDuration(spec) {
Expand Down
9 changes: 8 additions & 1 deletion src/util.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { badWords, parseDuration } from "./util";
import { badWords, formatANoun, parseDuration } from "./util";

describe("bad words filter", () => {
it("sort of works", () => {
Expand All @@ -17,6 +17,13 @@ describe("bad words filter", () => {
});
});

it("parseDuration works", () => {
expect(formatANoun("Set")).toBe("a Set");
expect(formatANoun("UltraSet")).toBe("an UltraSet");
expect(formatANoun("GhostSet")).toBe("a GhostSet");
expect(formatANoun("4Set")).toBe("a 4Set");
});

it("parseDuration works", () => {
expect(parseDuration("2w")).toBe(2 * 7 * 24 * 3600);
expect(parseDuration("3d")).toBe(3 * 24 * 3600);
Expand Down