エクスクルーシブ

Dateline <mv-dateline>

タイムゾーンを考慮した日時や期限の表示で、日付のずれを見逃しようがなくなります。

文化的リファレンス

八十日間世界一周、ジュール・ヴェルヌ(1872年、小説)。旅人は 1 日差で賭けに負けたと思い込みますが、東回りで日付変更線を越えたことで 1 日得していたと気づきます。同じ瞬間でも、彼のいる場所では日付が違っていたのです。UI では、すべての日時を両側の表記で同時に示し、閲覧者にとってその日時が何日に当たるかを明示するので、1 日違いで期限を逃す人はいなくなります。

仕組み

タイムゾーンを考慮した日時や期限の表示で、日付のずれを見逃しようがなくなります。絶対的な日時(オフセット付き、またはホームゾーンでのウォールタイムとしての datetime)とホームゾーンを渡すと、両側の表記を明示的な日付ずれチップ付きで 1 つの文にまとめます(「Fri, Oct 2, 5:00 PM PT, that’s Sat, Oct 3, 2:00 AM your time (+1 day)」)。出力には本物の <time datetime> 要素が使われます。inline バリアントは本文中に埋め込めます。card バリアントでは、さらに次の要素が加わります:絶対時刻で揃えたゾーンごとの 24 時間ストリップ(勤務時間、夜、深夜、週末に網掛けをし、各ゾーンの午前 0 時をその位置に描き、対象の日時をすべての行を貫く 1 本の線で示し、近い場合は現在時刻を破線で示します)、誰が勤務中か就寝中かがわかるチームのゾーン、テキストが変わるときにだけ更新されるライブのカウントダウン、夏時間の警告(対象日時から 1 週間以内の時計の切り替え、今日とは異なる時差、存在しないまたは 2 回発生するウォールタイム)、閲覧者のゾーンの選択、カレンダー用のヘルパー(リマインダーを任意で付けられる .ics のダウンロード、Google Calendar のリンク、コピー)。ゾーンの計算はすべて Intl.DateTimeFormat のみを使用し、任意の IANA ゾーン、30 分単位のオフセット、夏時間の切り替えに対応し、ロケールに応じて 12 時間制または 24 時間制で表示します。

カテゴリーデータ表示
タイプWeb Component(<mv-dateline>)
ステータス安定版
キット誠実なシステム状態
同時にインストールされるものbutton
Keywordsexclusive, culture, time-zone, timezone, date, time, deadline, countdown, world-clock, meeting-planner, dst, daylight-saving, intl, ics, calendar, google-calendar, distributed-team, remote, working-hours, relative-time

When to use

  • A deadline, launch or webinar is set in one time zone and read by people all over the world
  • An email, status page or changelog must state a maintenance window without anyone misreading the day
  • A distributed team needs to see who is working, off or asleep at a proposed meeting time
  • A recurring meeting falls in the weeks when regions switch daylight saving time on different dates

Avoid when

  • The user has to pick a date or time rather than read one → use Date Picker instead
  • The countdown guards a signed-in session that must be kept alive → use Hatch instead
  • The time is purely local (a store's opening hours for people standing in it): one plain time is clearer

インストール

node scripts/add.mjs dateline --out ./src/marvelous

Marvelous UI MCP サーバーを使う AI エージェント:install_components({ slugs: ["dateline"], target_dir: "<absolute path>/src/marvelous", framework: "react" })。

コピーされるファイル(依存関係を含む):tokens/tokens.css, core/base.css, components/button/button.css, core/dom.js, core/element.js, core/observe.js, components/dateline/dateline.js, components/dateline/dateline.css。

使い方

クイックスタート、動作する最小限のマークアップ:

<p>Submissions close <mv-dateline datetime="2026-10-02T17:00" zone="America/Los_Angeles"></mv-dateline>.</p>

基本となるマークアップです。ここから属性、data-*、CSS 変数でカスタマイズしてください:

<div id="dl-demo" style="width:min(100%,60rem);margin-inline:auto">
  <style>
    #dl-demo { display:grid; grid-template-columns:minmax(0,1fr); gap:1.25rem; align-content:start }
    #dl-demo .dl-bar { display:flex; align-items:center; justify-content:space-between; gap:.75rem 1.25rem; flex-wrap:wrap; padding:.75rem 1rem; border:1px solid var(--mv-border); border-radius:var(--mv-radius-xl); background:var(--mv-bg-subtle) }
    #dl-demo .dl-view { display:flex; align-items:center; gap:.5rem .75rem; flex-wrap:wrap; min-width:0; max-width:100% }
    #dl-demo .dl-scroll { max-width:100%; overflow-x:auto; scrollbar-width:none }
    #dl-demo .dl-k { color:var(--mv-fg-muted); font-size:.8125rem; font-weight:500 }
    #dl-demo .dl-tools { display:flex; align-items:center; gap:1rem; flex-wrap:wrap }
    #dl-demo .dl-grid { display:grid; grid-template-columns:minmax(0,1.1fr) minmax(0,1fr); gap:1.25rem; align-items:start }
    #dl-demo .dl-prose { display:grid; gap:.875rem; padding:1.25rem; border:1px solid var(--mv-border); border-radius:var(--mv-radius-xl); background:var(--mv-surface); box-shadow:var(--mv-shadow-sm) }
    #dl-demo .dl-prose h4 { margin:0; font-size:.8125rem; font-weight:500; color:var(--mv-fg-muted) }
    #dl-demo .dl-prose p { margin:0; font-size:.9375rem; line-height:1.65 }
    #dl-demo .dl-prose .dl-from { display:block; margin-bottom:.125rem; color:var(--mv-fg-subtle); font-size:.75rem }
    #dl-demo .dl-sep { height:1px; background:var(--mv-border) }
    #dl-demo .dl-log { display:flex; align-items:center; gap:.5rem; min-height:1.5rem; color:var(--mv-fg-muted); font-size:.75rem }
    @media (max-width:52rem) { #dl-demo .dl-grid { grid-template-columns:minmax(0,1fr) } }
  </style>

  <div class="dl-bar">
    <div class="dl-view">
      <span class="dl-k" id="dl-view-label">Preview as a viewer in</span>
      <div class="dl-scroll"><mv-segmented id="dl-viewer" aria-labelledby="dl-view-label" value="">
        <button value="">This device</button>
        <button value="Europe/Madrid">Madrid</button>
        <button value="America/New_York">New York</button>
        <button value="Asia/Singapore">Singapore</button>
        <button value="Pacific/Auckland">Auckland</button>
      </mv-segmented></div>
    </div>
    <div class="dl-tools">
      <label class="mv-choice">
        <input type="checkbox" role="switch" class="mv-switch" id="dl-24">
        <span class="mv-choice-text"><span class="mv-choice-title">24-hour clock</span></span>
      </label>
      <button type="button" class="mv-button" data-variant="outline" data-size="sm" id="dl-soon">Deadline in 15 s</button>
    </div>
  </div>

  <!-- A global deadline set in Pacific time, with the team's zones -->
  <mv-dateline id="dl-main" variant="card" data-dl-roll
    label="Global Hackathon · submissions close"
    datetime="2026-10-02T17:00" zone="America/Los_Angeles"
    zones="Europe/Paris Asia/Kolkata=Bengaluru Asia/Tokyo"
    countdown countdown-text="Closes in {time}" ended-text="Closed {time} ago"
    actions="google ics copy" picker reminder="2h"
    summary="Global Hackathon: submissions close"
    details="Upload your repository link and a 3-minute video on the submission portal."></mv-dateline>

  <div class="dl-grid">
    <!-- A recurring meeting in the weeks when Europe and the US switch clocks on different dates -->
    <mv-dateline id="dl-sync" variant="card"
      label="Weekly product sync"
      datetime="2026-10-26T09:00" zone="America/New_York"
      zones="Europe/London Asia/Singapore"
      countdown countdown-text="Starts in {time}" ended-text="Started {time} ago"
      duration="45m" actions="ics" location="Video call"></mv-dateline>

    <div class="dl-prose">
      <h4>In running text</h4>
      <p><span class="dl-from">Status page · Planned maintenance</span>
        The EU and US clusters go read-only on
        <mv-dateline id="dl-maint" data-dl-roll datetime="2026-10-04T23:00Z" zone="UTC" countdown></mv-dateline>
        for about 40 minutes.</p>
      <div class="dl-sep"></div>
      <p><span class="dl-from">Email · Tarnwick Conference 2027</span>
        Early-bird registration opens
        <mv-dateline id="dl-reg" data-dl-roll datetime="2026-10-01T09:00" zone="Pacific/Auckland" zone-label="Auckland"></mv-dateline>,
        with 300 seats at $149.</p>
      <div class="dl-sep"></div>
      <p class="dl-log" id="dl-log" aria-live="polite"><span class="mv-badge" data-variant="secondary" data-shape="pill" id="dl-log-badge">Events</span><span id="dl-log-text">Change the viewer zone or use the picker.</span></p>
    </div>
  </div>

  <script type="module">
    const root = document.getElementById("dl-demo");
    await customElements.whenDefined("mv-dateline");
    const all = [...root.querySelectorAll("mv-dateline")];
    const $ = (id) => document.getElementById(id);
    const log = (text, variant = "secondary", badge = "Event") => {
      $("dl-log-text").textContent = text;
      $("dl-log-badge").textContent = badge;
      $("dl-log-badge").dataset.variant = variant;
    };

    // Keep the demo in the future: roll wall-time dates forward by whole weeks.
    const pad = (n) => String(n).padStart(2, "0");
    for (const el of root.querySelectorAll("[data-dl-roll]")) {
      let guard = 0;
      while (el.moment && el.moment.getTime() < Date.now() + 36e5 && guard++ < 200) {
        const [date, rest] = el.datetime.split("T");
        const d = new Date(`${date}T00:00:00Z`);
        d.setUTCDate(d.getUTCDate() + 7);
        el.datetime = `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}T${rest}`;
      }
    }
    // The sync falls on the Monday after Europe's clock change (last Sunday of October).
    const sync = $("dl-sync");
    const europeGapMonday = (y) => {
      const d = new Date(Date.UTC(y, 9, 31));
      d.setUTCDate(31 - d.getUTCDay() + 1);
      return `${y}-10-${pad(d.getUTCDate())}T09:00`;
    };
    let y = new Date().getUTCFullYear();
    sync.datetime = europeGapMonday(y);
    if (sync.moment.getTime() < Date.now()) sync.datetime = europeGapMonday(y + 1);

    const viewer = $("dl-viewer");
    const setViewer = (zone) => { for (const el of all) el.viewerZone = zone || null; };
    viewer.addEventListener("mv-change", (e) => setViewer(e.detail.value));
    $("dl-24").addEventListener("change", (e) => { for (const el of all) el.clock = e.target.checked ? "24" : null; });

    root.addEventListener("mv-zone-change", (e) => {
      if (e.defaultPrevented) return;
      if (e.detail.source !== "user") { log(`Device zone changed to ${e.detail.zone}.`, "info", "Zone"); return; }
      // The picker of one card drives the whole page.
      setViewer(e.detail.automatic ? "" : e.detail.zone);
      viewer.value = [...viewer.querySelectorAll("button")].some((b) => b.value === (e.detail.automatic ? "" : e.detail.zone)) ? (e.detail.automatic ? "" : e.detail.zone) : viewer.value;
      log(`Showing times in ${e.detail.zone.replace(/_/g, " ")}.`, "info", "Zone");
    });
    root.addEventListener("mv-calendar", (e) => {
      if (e.detail.kind === "google") { e.preventDefault(); log("Google Calendar link ready (opening is disabled in this demo).", "info", "Calendar"); }
      else log(`.ics file downloaded${e.target.reminder ? `, with a reminder ${e.target.reminder} before` : ""}.`, "success", "Calendar");
    });
    root.addEventListener("mv-copy", (e) => log(`Copied: “${e.detail.text}”`, "success", "Copy"));

    const main = $("dl-main");
    const original = main.datetime;
    let restore = 0;
    main.addEventListener("mv-due", () => {
      log("Submissions are closed: the app can lock the form now.", "warning", "mv-due");
      clearTimeout(restore);
      restore = setTimeout(() => { if (main.isConnected) main.datetime = original; }, 6000);
    });
    $("dl-soon").addEventListener("click", () => {
      clearTimeout(restore);
      main.moment = Date.now() + 15_000;
      log("The deadline is now 15 seconds away: the countdown ticks every second in the last hour.", "info", "Countdown");
    });
  </script>
</div>

API

Attributes

NameタイプDefaultDescription
datetimeISO 8601 stringThe moment. With an offset (Z, +02:00) it is absolute; without one (2026-10-02T17:00) it is read as a wall time in zone, which is what people usually mean (“5 PM Pacific”), DST included. A date alone means midnight. A wall time that does not exist (spring forward) moves forward by the gap, one that happens twice (fall back) takes the first occurrence; both are explained in a note.
zoneIANA zone(the viewer's zone)Home zone of the moment: the organizer's, the store's, the server's (America/Los_Angeles, UTC…). Unknown zones fall back to the viewer's zone with a console warning.
zone-labelstring(city of the zone)Name of the home zone in the rows and notes (“HQ”, “San Francisco”). The sentence uses the short generic abbreviation when the locale has one (PT, ET, UTC), otherwise “<label> time”.
zonesstringExtra team zones for the card, space- or comma-separated, each optionally followed by =Label: "Europe/Paris Asia/Kolkata=Bengaluru" (use commas when labels contain spaces). Duplicates of the viewer or home zone are skipped. The zones property also accepts an array of strings or { zone, label, workHours }.
viewer-zoneIANA zone(device zone)Overrides the viewer's zone (a profile setting, a travel preview). Without it the device zone is used and re-checked when the tab regains focus or visibility (mv-zone-change with source "system").
variantinline | cardinlineinline: the sentence and its chips, to sit inside a paragraph. card: label, countdown, the two-line sentence, the zone strips, notes and the footer.
localeBCP 47en-USLanguage and formats of dates, times, units and lists.
clock12 | 24(from locale)Forces a 12-hour or 24-hour clock.
labelstringWhat the moment is (“Submissions close”): card heading (and accessible name of the card group), leading words of the inline sentence, and the calendar title unless summary is set.
countdownbooleanShows a live relative time (“in 2 days 4 hr”, “12 min 5 sec”, “3 hr ago”). Updates every second only in the last hour, otherwise once a minute, and pauses off screen or in a hidden tab.
countdown-text / ended-textstringin {time} / {time} agoCountdown templates before and after the moment: "Closes in {time}", "Closed {time} ago".
soontime ("24h", "90m", "2d")24hUnder this remaining time data-state becomes "soon" and the countdown turns amber.
work-hours / sleep-hours"H[:MM]-H[:MM]"9-18 / 22-7Local working and sleeping hours used for every zone's status and strip shading (sleep may wrap midnight). Saturdays and Sundays count as weekend.
spannumber (hours, 12-72)24Width of the strips, centered on the moment.
dst-windownumber (days)7A clock change in any shown zone within this many days of the moment adds a note (0 disables it). The “time difference differs from today” and wall-time notes are always on.
actions"google ics copy" (any subset)Card footer buttons: a prefilled Google Calendar link, an .ics download, and Copy (the plain sentence).
pickerbooleanCard footer select to show the times in another zone (every IANA zone, grouped by region, with its offset; first option = automatic). Emits a cancelable mv-zone-change, then sets viewer-zone.
summary / details / locationstringCalendar event title (default: label), description (the home time is appended) and location.
durationtime0Event length for the calendar helpers ("45m", "1h30m"); 0 for a deadline.
remindertimeAdds a VALARM this long before the moment to the .ics file ("2h").
data-stateupcoming | soon | past | invalidSet by the component (styleable).
data-shift"-1" | "0" | "+1" …Set by the component: calendar days between the viewer's date and the home date.

Properties

NameタイプDescription
momentDate | nullThe absolute moment. Setting a Date or epoch ms writes an ISO UTC datetime.
zonesstring | Array<string | { zone, label?, workHours? }>Team zones (see the attribute).
dayShiftnumber | nullViewer date minus home date, in days (read-only).
textstringThe full sentence, exactly as announced and copied (read-only).
notesstring[]Daylight-saving and wall-time warnings currently computed, also for the inline variant which does not display them (read-only).
snapshotArray<{ zone, label, roles, local, iso, offset, status, shift }>Every shown zone at the moment: local time text, ISO with offset, UTC offset in minutes, status (working | early | evening | asleep | weekend), day shift vs home (read-only).
currentViewerZonestringEffective viewer zone (read-only).
stringsPartial<Record<string, string>>Overrides for every visible text (keys: that, yourTime, alsoYourTime, sameDay, dayOne, dayOther, future, past, now, you, home, working, early, evening, asleep, weekend, vsHome, zonesTitle, notesTitle, gapChange, relAhead, relBehind, relSame, todayAhead, todayBehind, todaySame, forward, back, forwardMany, backMany, transition, before, after, lessThanDay, wallGap, wallTwice, pickerLabel, auto, google, ics, copy, copied, copyFailed, announceCopied, announceCopyFailed, homeTime, invalid, event). English defaults.

Methods

NameDescription
toICS()Returns an RFC 5545 calendar file (UTC times, stable UID, folded lines, optional VALARM).
googleCalendarUrl()Returns a prefilled Google Calendar event link.
copy(format?)Copies "text" (default, the sentence), "iso", "ics" or "google". Emits a cancelable mv-copy first. Resolves true on success.
refresh()Recomputes and re-renders now (e.g. after changing strings in place).

Events

NameDescription
mv-zone-changeThe viewer's zone changed. detail: { zone, previous, source: "user" | "system", automatic }. Cancelable when it comes from the picker (the select reverts); source "system" means the device zone changed (travel, OS setting) and viewer-zone is not set.
mv-dueThe moment was reached while the component was live. detail: { moment, late } (late: detected after the tab came back).
mv-calendarCancelable, before the Google Calendar link opens or the .ics downloads. detail: { kind: "google" | "ics", url, ics }. preventDefault() to run your own flow.
mv-copyCancelable, before copying. detail: { format, text }.

Content structure

NameDescription
(content)Optional fallback text (for no-JS or server rendering), replaced once the element is defined.

CSS classes

NameDescription
mv-dateline-sentenceThe sentence: .mv-dateline-lead (inline label), <time>.mv-dateline-home, .mv-dateline-join (.mv-dateline-dash + “that’s”), <time>.mv-dateline-local, .mv-dateline-you, .mv-dateline-shift[data-shift=ahead|behind|same]; .mv-dateline-paren holds visually hidden punctuation.
mv-dateline-head / -label / -countdownCard heading and the role="timer" countdown chip.
mv-dateline-zones / -list / -zoneZone rows (li[data-role=you|home|team][data-status]): -zone-info (-zone-name, -city, -tag, -zone-time, -status, -dot, -rel) and the aria-hidden -track (-bar with -seg[data-band=work|off|night|weekend], -midnight, -now, -mark; -ticks with -tick[data-day]).
mv-dateline-notesrole="note" box with the daylight-saving warnings (-notes-title, -notes-list).
mv-dateline-foot / -picker / -select / -actions / -actionFooter with the zone picker and the calendar buttons (data-action=google|ics|copy, data-copied after a copy).

CSS variables

NameDefaultDescription
--mv-dateline-shiftvar(--mv-warning)Tint of the day-shift chips and of the shifted local time.
--mv-dateline-markervar(--mv-accent)The moment line and dot across the strips.
--mv-dateline-workaccent 30% on surfaceWorking-hours shading.
--mv-dateline-offvar(--mv-bg-emphasis)Off-hours shading (weekends add a fine hatch).
--mv-dateline-nightdarker muted toneSleeping-hours shading.
--mv-dateline-info-width12.5remWidth of the zone info column beside the strips (stacked under 34rem of card width).

Accessibility

The sentence is the accessible text: real <time datetime> elements with the home zone's ISO offset and the viewer's, and the day shift spelled out as “(+1 day)” (parentheses visually hidden behind the chip, “−” read as minus), so screen readers get the same statement sighted users see and Copy puts on the clipboard. In the card, the strips are aria-hidden with pointer-events untouched; their text equivalent is the labelled list beside them (“At that moment”), one item per zone with its name, You / Home tag, local time, day shift and status (“Asleep · +9h vs home”). The card is a group named by its label. The countdown is a role="timer" element, whose implicit aria-live is off: it is read on demand and never announces each second; the component never announces time passing. Daylight-saving warnings are a role="note" block with a heading. The picker is a native select with a visible label, the actions are a real link (Google Calendar, new tab), a download link and a button; a copy is confirmed by a polite live region and a label change, and failures say so. Status is never color-only (dot plus words), shifts are text, and the chip, tags and strips keep borders or system colors in forced-colors mode. No animation is used, so reduced motion needs nothing. Everything visible is overridable through strings for other languages.

このページは AI で翻訳されています。翻訳の問題を報告