把这段提示词交给你的 Agent,看看它会给出什么评价。
你的 Agent
Temporal 与 Intl 让浏览器原生具备真正的时区支持、不受夏令时干扰的日历运算与深度本地化能力。Native Dates 将它们封装为易读、不可变的 API,仅 14.9 kB br。
today()tomorrow()yesterday()CalendarDate2026年11月25日.add(1, 'week').next('monday').next('wednesday').next('friday').next('sunday')CalendarDate2026年12月2日.at('5pm', 'Asia/Shanghai').at('8am', 'Europe/London').at('3pm', 'Europe/Paris').at('6:45pm', 'Asia/Tokyo')DateTime2026年12月2日 GMT+8 17:00.in('Europe/London').in('Australia/Sydney').in('Asia/Tokyo').in('America/Sao_Paulo')DateTime2026年12月2日 GMT+0 09:00time('9:20am')time('10:00pm')time('6:40am')Time09:20.plus(8, 'hours').plus(45, 'minutes').plus(3, 'hours')Time17:20.round(15, 'minutes').round('hour')Time17:15.format('HH:mm').format('short')string'17:15'duration('1h 30m')duration('45 minutes')duration('2 days and 6 hours')Duration1小时30分钟.plus(45, 'minutes').plus(3, 'hours').plus(1, 'day')Duration2小时15分钟.times(2).times(3)Duration4小时30分钟.format('narrow').format('short').format('digital')string'4小时30分钟'dateRange('2026-05-01', '2 weeks')dateRange('2026-01-01', '2026-01-14')dateRange('2026-11-01', '2026-11-30')DateRange2026/5/1 – 2026/5/14.count('weekdays').count('weekends').count('mondays').count()number10monthYear('12/26')monthYear('11/27')monthYear('04/26')YearMonth2026年12月.add(3, 'months').add(1, 'year').minus(1, 'month')YearMonth2027年3月.end.daysInMonth.isPast()CalendarDate2027年3月31日monthDay('10/17')monthDay('02/29')monthDay('12/25')MonthDay10月17日.next().in(2028).previous()CalendarDate2027年10月17日.fromNow().format('full').format('dddd')string'1年后'一次配置(或直接使用浏览器默认语言),“上午/下午”前置、不补零的年月日、纪念日与周一至周日表头都在全局自动生效;需要传统农历与干支纪年时再按需传入历法标签,语言包体积为 0 kB。
configure({ locale: 'zh-CN' });客户端启动时配置一次(省略则跟随浏览器语言),服务端按请求调用 .locale(tag)
无需在每次调用时重复传入 zh-CN,日期与 MonthDay 直接输出地道中文。
date('2026-05-01').text + ' · ' + monthDay('05-01').format('long')12 小时制下自动输出中文“上午/下午”并置于小时数字之前,无需手写英文 AM/PM 映射。
time('09:30').format('Ah:mm')仅在切换历法时传入历法标签,春节正月初一与干支年自动对齐。
date('2026-02-17').format('long', 'zh-CN-u-ca-chinese')按中文地区习惯从周一开始并正确输出“周日”,告别手写映射表或拼接出“周七”的隐患。
weekdayNames('short').join(' · ')别再像 1995 年那样,花时间死记 Date 的各种缺陷和边界情况。
Date 始于 1995 年
const day = new Date('2026-09-01T00:00+08:00');day.toISOString().slice(0, 10);
'2026-08-31' 早了一天
native-dates 基于 Temporal
date('2026-09-01');CalendarDate {month: 9, day: 1, year: 2026, dayOfWeek: 2}
为什么? 在东八区对本地零点调用 toISOString() 会回退到 UTC 前一天 16:00,截出 2026-08-31。CalendarDate 只表示日历日期,绝不会因时区偏移而跨天。
Date 始于 1995 年
const end = new Date(2026, 0, 31);
end.setMonth(1);
end.toDateString();
'Tue Mar 03 2026' 晚了三天
native-dates 基于 Temporal
date('2026-01-31').plus(1, 'month');CalendarDate {month: 2, day: 28, year: 2026, dayOfWeek: 6}
为什么? Date 会把 2 月 31 日溢出进位到 3 月 3 日。Temporal 则会将其限制到 2 月末。
Date 始于 1995 年
const nine = new Date('2026-03-28T09:00+00:00');const next = new Date(nine.getTime() + 24 * 60 * 60 * 1000);
next.toLocaleTimeString('zh-CN', { timeZone: 'Europe/London' });'10:00:00' 晚了一小时
native-dates 基于 Temporal
datetime('2026-03-28T09:00', 'Europe/London').plus(1, 'day');DateTime {month: 3, day: 29, year: 2026, hour: 9, minute: 0, …}
为什么? 中国不实行夏令时,但伦敦会在 3 月最后一个周日拨快一小时进入夏令时。直接加 24 小时会在次日变成 10 点,而 plus(1, 'day') 始终保持当地时间 9 点。
Date 始于 1995 年
const start = new Date(2026, 8, 1);
const due = start;
due.setDate(31);
start.toDateString();
'Thu Oct 01 2026' 被原地篡改
native-dates 基于 Temporal
const start = date('2026-09-01');const due = start.plus(30, 'days');
start;
CalendarDate {month: 9, day: 1, year: 2026, dayOfWeek: 2}
为什么? setDate() 会原地修改 Date 实例。native-dates 的所有值都是不可变的,plus() 始终返回新实例。
日期库常在性能剖析中成为瓶颈,但一直没人做过同场基准测试来弄清究竟是谁慢、慢在哪里,所以我们自己做了一套。亲自动手跑一遍,或者把你的库加进来一起测。
| 任务 | native-dates1.0.0 | date-fns4.4.0 | Day.js1.11.23 | Luxon3.7.2 | Moment2.31.0 | Tempo1.5.0 |
|---|---|---|---|---|---|---|
| 解析 ISO 字符串日历日期与 UTC 时间戳 | 7.2 ms | 15.1 ms | 3.3 ms接受 2 月 31 日 | 14.2 ms | 28.1 ms | 3.0 ms最快接受 2 月 31 日 |
| 占位符模板格式化UTC 下的 YYYY-MM-DD HH:mm:ss | 3.6 ms | 21.5 ms | 4.9 ms | 5.9 ms | 3.4 ms最快 | 538 ms |
| 按语言环境格式化跨多种语言环境与时区 | 8.9 ms最快 | 159 ms | 145 ms | 19.3 ms | 145 ms | 1,069 ms |
| 首次按语言环境格式化未缓存过的语言环境与时区组合 | 1.4 ms最快 | 22.4 ms | 20.8 ms | 5.3 ms | 21.1 ms | 175 ms |
| 日历运算加减天数与月份,计算月末与周边界 | 14.0 ms | 5.9 ms最快 | 20.3 ms | 38.7 ms | 12.0 ms | 8.8 ms |
| 时区运算跨夏令时加减天数,在不同时区间转换 | 8.3 ms最快 | 22.3 ms | 119 ms正确率 96.9% | 28.4 ms | 16.5 ms | 497 ms正确率 0% |
| 求差与排序计算小时差与天数差,按时间先后排序 | 3.0 ms | 17.4 ms | 4.7 ms | 24.8 ms | 6.1 ms | 2.4 ms最快 |
| 相对时间用两种语言生成如“3 天前”的短语 | 0.9 ms最快 | 3.6 ms | 7.3 ms | 69.3 ms | 18.7 ms | 3.6 ms |
| 订单表格解析、筛选、排序并渲染来自 API 的行数据 | 1.7 ms最快 | 20.5 ms | 15.7 ms | 27.9 ms | 11.9 ms | 84.6 ms |
| 月历视图生成含周末与事件的全年 12 个月历网格 | 1.4 ms最快 | 1.5 ms | 3.4 ms | 7.2 ms | 2.8 ms | 112 ms |
| 预约时段生成跨夏令时周的半小时可预约时段 | 6.4 ms最快 | 126 ms | 1,444 ms | 13.3 ms | 10.5 ms | 12.6 ms |
| 冷启动导入库并绘制首批数据行 | 16.8 ms最快 | 19.1 ms | 20.0 ms | 33.7 ms | 26.3 ms | 39.3 ms |
| 全部任务平均耗时,以 native-dates 为 1× 基准 | 1×最快 | 4.2× | 5.8× | 4.4× | 3.1×第二快 | 10.9× |
在无头 Chrome 159 中经 15 轮测试取中位数,测于 2026年11月24日。
查看完整结果中国全年固定 UTC+8,但伦敦每年会切换夏令时,两地时差一年要变动 2 次。借助浏览器内置的 IANA 时区数据库,无需打包任何时区数据即可自动换算。
不再把所有场景都塞进 JavaScript 的 Date,而是按你对时间的直觉,分别使用专用的不可变类型。
date('2026-11-16')Temporal.PlainDate.from('2026-11-16')new Date(2026, 10, 16) // month 10 is NovemberTemporal.PlainDateDatetime('9:30am')Temporal.PlainTime.from('09:30')570 // minutes since midnightTemporal.PlainTimenumberdatetime('2026-11-16T09:30', 'Asia/Shanghai')Temporal.ZonedDateTime.from('2026-11-16T09:30[Asia/Shanghai]'){ at: new Date('2026-11-16T01:30Z'), zone: 'Asia/Shanghai' }Temporal.ZonedDateTimeDate + stringduration('1h 30m')Temporal.Duration.from({ hours: 1, minutes: 30 })90 * 60 * 1000 // millisecondsTemporal.Durationnumbernow()Temporal.Now.zonedDateTimeISO()new Date()Temporal.NowDateyearMonth('2026-11')Temporal.PlainYearMonth.from('2026-11')new Date(2026, 10, 1) // fake 1st, month 10Temporal.PlainYearMonthDatemonthDay('10/17')Temporal.PlainMonthDay.from({ month: 10, day: 17 })new Date(2000, 9, 17) // fake leap yearTemporal.PlainMonthDayDatedateRange('2026-09-01', '2026-09-14')Temporal.PlainDate.from('2026-09-01')
Temporal.PlainDate.from('2026-09-14')[new Date(2026, 8, 1), new Date(2026, 8, 14)] // 8 is September2 × Temporal.PlainDate2 × DatetimeRange('9:00am', '5:00pm')Temporal.PlainTime.from('09:00')
Temporal.PlainTime.from('17:00')[540, 1020] // minutes since midnight2 × Temporal.PlainTime2 × numberTemporal 在设计上显式且偏底层。不妨对比以下四个常见操作在 native-dates、原生 Temporal 与 JS Date 中的写法。
const meeting = today().next('monday').at('9:30am', 'Asia/Shanghai');const today = Temporal.Now.plainDateISO();
// the next Monday after today
const ahead = (8 - today.dayOfWeek) % 7 || 7;
const meeting = today.add({ days: ahead }).toZonedDateTime({
timeZone: 'Asia/Shanghai',
plainTime: '09:30',
});const today = new Date();
// the next Monday after today
const ahead = (8 - today.getDay()) % 7 || 7;
const day = today.getDate() + ahead;
// Date has no time zones: take 9:30 as UTC, format in Shanghai,
// and shift by the offset difference
const utc = Date.UTC(today.getFullYear(), today.getMonth(), day, 9, 30);
const zone = { timeZone: 'Asia/Shanghai' };
// the swedish locale prints dates the way Date.parse reads them
const there = new Date(utc).toLocaleString('sv-SE', zone);
const offset = utc - Date.parse(there.replace(' ', 'T') + 'Z');
const meeting = new Date(utc + offset);const invite = meeting.in('Australia/Sydney').format('full');const invite = meeting
.withTimeZone('Australia/Sydney')
.toLocaleString(undefined, { dateStyle: 'full', timeStyle: 'short' });const invite = meeting.toLocaleString(undefined, {
dateStyle: 'full',
timeStyle: 'short',
timeZone: 'Australia/Sydney',
});const due = today().plus(1, 'month').endOf('month');const nextMonth = Temporal.Now.plainDateISO().add({ months: 1 });
const due = nextMonth.with({ day: nextMonth.daysInMonth });const today = new Date(); // day 0 of a month is the last day of the month before it const due = new Date(today.getFullYear(), today.getMonth() + 2, 0);
const wait = now().until(meeting).round('minute').format();// Temporal.until() throws across time zones when largestUnit >= 'day'
const here = Temporal.Now.zonedDateTimeISO();
const until = here.until(meeting.withTimeZone(here.timeZoneId), {
largestUnit: 'year',
smallestUnit: 'minute',
roundingMode: 'halfExpand',
});
const wait = until.toLocaleString(undefined, { style: 'long' });// round to the minute, then step day-by-day across any DST transition
const minutes = Math.round((meeting - Date.now()) / 60_000);
const from = new Date(meeting - minutes * 60_000);
const after = (days) => new Date(from).setDate(from.getDate() + days);
let days = 0;
while (after(days + 1) <= meeting) { days++; }
const rest = (meeting - after(days)) / 60_000;
const hours = Math.floor(rest / 60);
const words = new Intl.DurationFormat(undefined, { style: 'long' });
const wait = words.format({ days, hours, minutes: rest % 60 });核心库开箱即用,内置 9 种时间类型、相对时间、本地化格式化等一切常用能力;按需引入插件即可扩展更多功能。
切换预览时区即可模拟在其他城市运行的效果,也可以直接在线编辑代码。
import { tomorrow } from 'native-dates';
import { CITIES } from './cities.js';
const input = document.querySelector('input');
const summary = document.querySelector('#summary');
const list = document.querySelector('ul');
function render() {
const meeting = tomorrow().at(input.value);
summary.textContent = meeting.format('full');
list.innerHTML = CITIES.map((zone) => {
const there = meeting.in(zone);
const sameDay = there.date.equals(meeting.date);
return `<li>
<code>${zone}</code>
<b>${there.format('time')}</b>
<span class="muted">${sameDay ? '' : there.format({ weekday: 'long' })}</span>
</li>`;
}).join('');
}
input.addEventListener('input', render);
render();
正在启动…
经得起检验的严谨代码
Install `native-dates` in a scratch directory, look through its source and types, and try a few everyday date and timezone tasks in Node. Based on what you actually see in the code and API, would you pick it over `date-fns`, `luxon`, or `dayjs` for a new project, or stick with one of those? Give me your honest take and why.I’d pick native-dates. Everything else wraps Date, so choosing one of them now probably just means a second migration to Temporal in a year or two.
Every date helper collapsed into a one-liner — and if it ever stalls, the fallback is just raw Temporal, not a rewrite.
Finally don’t have to ship locale JSON just to parse a European form date.
I ran the package through DST shifts, half-open slots, and month-end clamping. Having real CalendarDate and DateRange types removes way more risky glue code than the alternatives.
Deletes all the fragile hand-rolled DST loops, and every noun drops to .toTemporal() when I need it.Modern browsers pay zero polyfill bytes, and Safari just lazy-loads Temporal until it lands.
Tested it expecting a catch, and it held up everywhere. Separate civil dates and half-open ranges quietly eliminate a whole class of timezone bugs.
One frozen, immutable API for zones, DST, and ranges — without stacking six plugins first.
把这段提示词交给你的 Agent,看看它会给出什么评价。
你的 Agent
以上均为直接向各模型输入无前置上下文提示词后得到的原话摘录。商标与模型名称归各自所有者所有,不代表任何官方背书。
npm i native-datesnpx @native-dates/setup@latest