Skip to content

Commit c34b18c

Browse files
author
Bruno Bergher
committed
It turns out using day.js was better
1 parent cffc22e commit c34b18c

File tree

25 files changed

+94
-397
lines changed

25 files changed

+94
-397
lines changed

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/task/Task.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ import crypto from "crypto"
55
import EventEmitter from "events"
66

77
import { Anthropic } from "@anthropic-ai/sdk"
8+
import dayjs from "dayjs"
9+
import relativeTime from "dayjs/plugin/relativeTime"
810
import delay from "delay"
911
import pWaitFor from "p-wait-for"
1012
import { serializeError } from "serialize-error"
1113

14+
// Initialize day.js plugins
15+
dayjs.extend(relativeTime)
16+
1217
import {
1318
type TaskLike,
1419
type TaskEvents,
@@ -1191,25 +1196,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
11911196

11921197
let newUserContent: Anthropic.Messages.ContentBlockParam[] = [...modifiedOldUserContent]
11931198

1194-
const agoText = ((): string => {
1195-
const timestamp = lastClineMessage?.ts ?? Date.now()
1196-
const now = Date.now()
1197-
const diff = now - timestamp
1198-
const minutes = Math.floor(diff / 60000)
1199-
const hours = Math.floor(minutes / 60)
1200-
const days = Math.floor(hours / 24)
1201-
1202-
if (days > 0) {
1203-
return `${days} day${days > 1 ? "s" : ""} ago`
1204-
}
1205-
if (hours > 0) {
1206-
return `${hours} hour${hours > 1 ? "s" : ""} ago`
1207-
}
1208-
if (minutes > 0) {
1209-
return `${minutes} minute${minutes > 1 ? "s" : ""} ago`
1210-
}
1211-
return "just now"
1212-
})()
1199+
const agoText = dayjs(lastClineMessage?.ts ?? Date.now()).fromNow()
12131200

12141201
if (responseText) {
12151202
newUserContent.push({

src/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@
431431
"cheerio": "^1.0.0",
432432
"chokidar": "^4.0.1",
433433
"clone-deep": "^4.0.1",
434+
"dayjs": "^1.11.13",
434435
"default-shell": "^2.2.0",
435436
"delay": "^6.0.0",
436437
"diff": "^5.2.0",

webview-ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"clsx": "^2.1.1",
4040
"cmdk": "^1.0.0",
4141
"date-fns": "^4.1.0",
42+
"dayjs": "^1.11.13",
4243
"debounce": "^2.1.1",
4344
"fast-deep-equal": "^3.1.3",
4445
"fzf": "^0.5.2",

webview-ui/src/components/history/TaskItemFooter.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react"
22
import type { HistoryItem } from "@roo-code/types"
3-
import { formatTimeAgo } from "@/utils/format"
3+
import { formatDate, formatTimeAgo } from "@/utils/format"
44
import { CopyButton } from "./CopyButton"
55
import { ExportButton } from "./ExportButton"
66
import { DeleteButton } from "./DeleteButton"
@@ -17,20 +17,18 @@ const TaskItemFooter: React.FC<TaskItemFooterProps> = ({ item, variant, isSelect
1717
return (
1818
<div className="text-xs text-vscode-descriptionForeground flex justify-between items-center">
1919
<div className="flex gap-2 items-center text-vscode-descriptionForeground/60">
20-
{/* Datetime with time-ago format */}
21-
<StandardTooltip content={new Date(item.ts).toLocaleString()}>
22-
<span className="capitalize">{formatTimeAgo(item.ts)}</span>
20+
<StandardTooltip content={formatDate(item.ts)}>
21+
<span>{formatTimeAgo(item.ts)}</span>
2322
</StandardTooltip>
2423
<span>·</span>
25-
{/* Cost */}
24+
2625
{!!item.totalCost && (
2726
<span className="flex items-center" data-testid="cost-footer-compact">
2827
{"$" + item.totalCost.toFixed(2)}
2928
</span>
3029
)}
3130
</div>
3231

33-
{/* Action Buttons for non-compact view */}
3432
{!isSelectionMode && (
3533
<div className="flex flex-row gap-0 items-center text-vscode-descriptionForeground/60 hover:text-vscode-descriptionForeground">
3634
<CopyButton itemTask={item.task} />

webview-ui/src/i18n/locales/ca/common.json

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/de/common.json

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/en/common.json

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,5 @@
6767
"editMessage": "Edit Message",
6868
"editWarning": "Editing this message will delete all subsequent messages in the conversation. Do you want to proceed?",
6969
"proceed": "Proceed"
70-
},
71-
"time_ago": {
72-
"just_now": "just now",
73-
"seconds_ago": "{{count}} seconds ago",
74-
"minute_ago": "a minute ago",
75-
"minutes_ago": "{{count}} minutes ago",
76-
"hour_ago": "an hour ago",
77-
"hours_ago": "{{count}} hours ago",
78-
"day_ago": "a day ago",
79-
"days_ago": "{{count}} days ago",
80-
"week_ago": "a week ago",
81-
"weeks_ago": "{{count}} weeks ago",
82-
"month_ago": "a month ago",
83-
"months_ago": "{{count}} months ago",
84-
"year_ago": "a year ago",
85-
"years_ago": "{{count}} years ago"
8670
}
8771
}

webview-ui/src/i18n/locales/es/common.json

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/i18n/locales/fr/common.json

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)