diff --git a/deno.jsonc b/deno.jsonc index 26a84f8..ef4ee0c 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -1,6 +1,6 @@ { "lock": false, - "version": "0.0.2", + "version": "0.0.3", "tasks": { "check": "deno fmt --check && deno lint && deno check **/*.ts && deno check **/*.tsx", "cli": "echo \"import '\\$fresh/src/dev/cli.ts'\" | deno run --unstable -A -", diff --git a/lib/agent_version.ts b/lib/agent_version.ts index e534be6..0b680af 100644 --- a/lib/agent_version.ts +++ b/lib/agent_version.ts @@ -22,7 +22,7 @@ export interface AgentVersion extends SemVer { } // SemVer compatibility requires that we return a 0 for unspecified parts. -const safeParseInt = (s?: string): number => { +export const safeParseInt = (s?: string): number => { const num = s ? parseInt(s, 10) : 0 if (isNaN(num)) { @@ -49,7 +49,7 @@ const parse = (value: string): AgentVersion => { } const toSemVer = (version: AgentVersion): SemVer => { - return parseSemVer(version.parts.join('.')) + return parseSemVer(version.parts.map((v) => v ? v : '0').join('.')) } const format = (version: AgentVersion, length?: number): string => { diff --git a/routes/index.tsx b/routes/index.tsx index 5245398..5c7b181 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -4,7 +4,7 @@ import type { Handlers, PageProps } from '$fresh/server.ts' import { type Agent, getAgentReleaseInfo } from '../lib/agent.ts' import { formatDateYearMonth, humanizeDurationSince, randInterjection, toOrdinal } from '../lib/utils.ts' import { getFamilyName, getGlobalUsageStats, getNorthAmericaUsageStats } from '../lib/family.ts' -import AgVer from '../lib/agent_version.ts' +import AgVer, { safeParseInt } from '../lib/agent_version.ts' import UaInputSubmit from '../islands/ua_input_submit.tsx' import type { UserAgent } from '$std/http/user_agent.ts' @@ -48,17 +48,28 @@ const AgentIdentification = ({ ok, version, userAgent, name, source }: RenderDat ) } -const AgentReleaseAge = ({ name, releaseDate }: RenderData) => { - if (!releaseDate) return null - - const { date, version } = releaseDate +const AgentReleaseAge = ({ name, version, releaseDate, asOf, currentVersion }: RenderData) => { + if (!releaseDate?.date) { + // if the agent version is beyond the current version, it's likely just been released. + const veryRecent = (currentVersion && version) ? safeParseInt(currentVersion) < version.major : false + + // if the current date formatted matches the asOf date formatted, we're still in the same month, so use "in" not "after" + const likelyReleased = formatDateYearMonth(asOf || new Date()) + const inOrAfter = formatDateYearMonth(new Date()) === likelyReleased + + return ( +
+ {veryRecent + ? <>That version is brand new! It was likely released {inOrAfter ? 'in' : 'after'} {formatDateYearMonth(asOf || new Date())}.> + : <>That version is either very old or very new. That's all we know.>} +
+ ) + } return (- {name} {version} - {date - ? ` was released in ${formatDateYearMonth(date)}; it's ${humanizeDurationSince(date)} old.` - : ` hasn't officially been released yet. Far out.`} + {name} {releaseDate.version} was released in {formatDateYearMonth(releaseDate.date)};{' '} + <>it's {humanizeDurationSince(releaseDate.date)} old.>
) }