أعطِ وكيلك هذا الموجّه وشاهد ما يعود به إليك.
وكيلك
تمنح واجهتا Temporal وIntl المتصفح مناطق زمنية حقيقية، وحسابات تقويمية آمنة عند تغيّر التوقيت الصيفي، وتخصيصًا دقيقًا للإعدادات المحلية. وتجمعهما Native Dates في واجهة برمجية مقروءة وغير قابلة للتعديل بحجم 14.9 kB br.
today()tomorrow()yesterday()CalendarDate٢٥/١١/٢٠٢٦.add(1, 'week').next('monday').next('wednesday').next('friday').next('sunday')CalendarDate٠٢/١٢/٢٠٢٦.at('11am', 'Africa/Cairo').at('8am', 'Europe/London').at('3pm', 'Europe/Paris').at('6:45pm', 'Asia/Tokyo')DateTime٢ ديسمبر ٢٠٢٦، ١١:٠٠ ص غرينتش+٢.in('Europe/London').in('Asia/Tokyo').in('Asia/Kolkata').in('America/Sao_Paulo')DateTime٢ ديسمبر ٢٠٢٦، ٩:٠٠ ص غرينتش+٠time('9:20am')time('10:00pm')time('6:40am')Time٩:٢٠ ص.plus(8, 'hours').plus(45, 'minutes').plus(3, 'hours')Time٥:٢٠ م.round(15, 'minutes').round('hour')Time٥:١٥ م.format('HH:mm').format('short')string'17:15'duration('1h 30m')duration('45 minutes')duration('2 days and 6 hours')Durationساعة و٣٠ دقيقة.plus(45, 'minutes').plus(3, 'hours').plus(1, 'day')Durationساعتان و١٥ دقيقة.times(2).times(3)Duration٤ ساعات و٣٠ دقيقة.format('narrow').format('short').format('digital')string'٤ س و٣٠ د'dateRange('2026-05-01', '2 weeks')dateRange('2026-01-01', '2026-01-14')dateRange('2026-11-01', '2026-11-30')DateRange١/٥/٢٠٢٦ – ١٤/٥/٢٠٢٦.count('weekdays').count('weekends').count('mondays').count()number10monthYear('12/26')monthYear('11/27')monthYear('04/26')YearMonthديسمبر ٢٠٢٦.add(3, 'months').add(1, 'year').minus(1, 'month')YearMonthمارس ٢٠٢٧.end.daysInMonth.isPast()CalendarDate٣١/٠٣/٢٠٢٧dayMonth('17/10')dayMonth('29/02')dayMonth('25/12')MonthDay١٧ أكتوبر.next().in(2028).previous()CalendarDate١٧/١٠/٢٠٢٧.fromNow().format('full').format('dddd')string'خلال سنة واحدة'بضبط الإعداد المحلي مرّة واحدة (أو تركه للغة المتصفح)، تعمل صيغة المثنى «يومان» وصيغ العدد الست والأرقام العربية والنطاقات في كل مكان تلقائيًا، مع تمرير وسم مخصّص فقط عند التحويل إلى التقويم الهجري أو إعداد محلي آخر، بزيادة 0 كيلوبايت على الحزمة.
configure({ locale: 'ar-EG' });اضبط الإعداد المحلي مرّة عند بدء التطبيق (أو اتركه للغة المتصفح)، أو مرّر .locale(tag) لكل طلب على الخادم
يظهر المفرد والمثنى «يومان» دون رقم، مع جمع القلّة من 3 إلى 10 والتمييز المنصوب من 11 إلى 99.
[1, 2, 5, 11].map((n) => days(n).text).join(' · ')اختصار الشهر والسنة المشتركين في نطاق واحد متسق مع اتجاه الكتابة دون تكرار الإعداد المحلي.
dateRange('2026-05-01', '2026-05-05').format('long')يسري الإعداد المحلي الافتراضي تلقائيًا، مع إمكانية إرفاق ar-MA بالقيمة عند الحاجة إلى الأرقام المغاربية و«ماي».
date('2026-05-01').format('long') + ' · ' + date('2026-05-01').locale('ar-MA').format('long')عرض التاريخ الهجري الكامل بدقة عند تمرير وسم التقويم الهجري.
date('2026-05-01').format('long', 'ar-SA-u-ca-islamic-umalqura')لا تُضِع وقتك في حفظ أخطاء Date وحالاته الشاذة وكأننا ما زلنا في عام 1995.
Date منذ 1995
const day = new Date('2026-09-01T00:00+03: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+3 صيفًا) يعود التاريخ إلى 21:00 UTC من اليوم السابق فيصبح 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 يوم 31 فبراير ليقفز إلى 3 مارس، بينما يقيّده Temporal بآخر يوم في فبراير.
Date منذ 1995
const nine = new Date('2026-04-23T09:00+02:00');const next = new Date(nine.getTime() + 24 * 60 * 60 * 1000);
next.toLocaleTimeString('ar-EG', { timeZone: 'Africa/Cairo' });'١٠:٠٠:٠٠ ص' متأخر بساعة
native-dates على Temporal
datetime('2026-04-23T09:00', 'Africa/Cairo').plus(1, 'day');DateTime {month: 4, day: 24, year: 2026, hour: 9, minute: 0, …}
لماذا؟ تبدأ مصر التوقيت الصيفي في الجمعة الأخيرة من أبريل فيصبح اليوم 23 ساعة. إضافة 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تقبل 31 فبراير | 14.2 ms | 28.1 ms | 3.0 msالأسرعتقبل 31 فبراير |
| التنسيق بأنماط الرموزYYYY-MM-DD HH:mm:ss بتوقيت UTC | 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 ms96.9% صحيح | 28.4 ms | 16.5 ms | 497 ms0% صحيح |
| الفروق والفرزفروق بالساعات والأيام، وفرز زمني | 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 |
| تقويم شهريسنة من الشبكات الشهرية مع عطلات نهاية الأسبوع والأحداث | 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× |
القيم الوسيطة عبر 15 جولة في Chrome 159 بدون واجهة، قِيست في 24 نوفمبر 2026.
عرض النتائج الكاملةتُغيّر لندن والقاهرة التوقيت الصيفي في مواعيد مختلفة في الربيع والخريف، فيتبدّل الفارق الزمني 4 مرات في السنة دون بايت واحد إضافي في حزمتك.
بدل تحميل كائن Date في JavaScript فوق طاقته، استخدم أنواعًا مخصّصة غير قابلة للتعديل توافق كل طريقة تفكّر بها في الوقت.
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', 'Africa/Cairo')Temporal.ZonedDateTime.from('2026-11-16T09:30[Africa/Cairo]'){ at: new Date('2026-11-16T07:30Z'), zone: 'Africa/Cairo' }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.PlainYearMonthDatedayMonth('17/10')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 × numberصُمّم Temporal ليكون صريحًا ومنخفض المستوى. قارن العمليات الأربع نفسها بين native-dates وTemporal الخام وDate في JavaScript.
const meeting = today().next('monday').at('9:30am', 'Africa/Cairo');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: 'Africa/Cairo',
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 Cairo,
// and shift by the offset difference
const utc = Date.UTC(today.getFullYear(), today.getMonth(), day, 9, 30);
const zone = { timeZone: 'Africa/Cairo' };
// 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('Asia/Dubai').format('full');const invite = meeting
.withTimeZone('Asia/Dubai')
.toLocaleString(undefined, { dateStyle: 'full', timeStyle: 'short' });const invite = meeting.toLocaleString(undefined, {
dateStyle: 'full',
timeStyle: 'short',
timeZone: 'Asia/Dubai',
});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.
أعطِ وكيلك هذا الموجّه وشاهد ما يعود به إليك.
وكيلك
مقتطفات حرفية من وكلاء تلقّوا موجّه المراجعة المباشرة. الشعارات وأسماء النماذج مملوكة لأصحابها؛ ولا يعني عرضها أي تزكية رسمية.
npm i native-datesnpx @native-dates/setup@latest