Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
DenoのためのDateTimeライブラリPtera
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Takuro
August 18, 2021
Programming
480
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
DenoのためのDateTimeライブラリPtera
https://yumenosora.connpass.com/event/220025/の発表資料
Takuro
August 18, 2021
More Decks by Takuro
See All by Takuro
RustのSchema_First_GraphQLライブラリrusty-gqlを作った話.pdf
tak_iwamoto
0
140
STORES予約を支えるフロントエンド技術
tak_iwamoto
2
4.9k
Other Decks in Programming
See All in Programming
Agents on Rails - Rails at Scale 2026
irinanazarova
0
530
APNsからLive Activityを開始する話
yumnumm
0
160
Androidだけじゃない、DroidKaigiで広がった私の技術スタック
akkeylab
0
120
CodeRabbitの効果検証と過ごしてみた3ヶ月
armondando
0
220
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
Workers Cache を知る
syumai
0
350
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
360
すこし踏み込む CancellationToken
htkym
2
1.7k
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
110
パーソナライズPodcastを作った話
repunit11
0
130
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
540
速く作れる。その次は、速く確かめられる開発へ 〜AIネイティブ開発を支える、Shift Down〜 / Can build fast. Next, moving to development where we can verify fast.
rkaga
8
5.7k
Featured
See All Featured
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Designing Experiences People Love
moore
143
24k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
310
Between Models and Reality
mayunak
4
490
The Cost Of JavaScript in 2023
addyosmani
55
10k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
570
Ethics towards AI in product and experience design
skipperchong
2
420
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
260
The untapped power of vector embeddings
frankvandijk
2
1.9k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Transcript
Deno の DateTime ライブラリ Ptera を作った話 Takuro Iwamoto
自己紹介 Takuro Iwamoto Software Engineer at STORES 予約 最近の興味は Deno
と Rust Twitter: @tak_rockbook
Ptera DateTime Library For Deno Fully written in Deno Inspired
By Day.js, Luxon and Moment.js import { datetime } from "https://deno.land/x/ptera/mod.ts"; // parse ISO 8601 datetime("2021-06-30T21:15:30.200"); // timezone datetime().toZonedTime("Asia/Tokyo"); // locale datetime().setLocale("fr");
Why does Ptera exist? Node.js の DateTime ライブラリも Deno で使用できる。
単純に Deno で何かライブラリを書いてみたかった! Day.js や Luxon のように独自のクラスを提供している Deno のライブラリはなかった。 deno_std/datetime に date-fns 的な Date クラスに対する utilities は存在している。 dayjs は Deno で使用する際に補完が効かない。 import dayjs from "https://cdn.skypack.dev/
[email protected]
"; import { DateTime } from "https://cdn.skypack.dev/luxon"; import { format } from "https://deno.land/x/date_fns/index.js"; const dayjsDate = dayjs(); const luxonDate = DateTime.now(); format(new Date(), "'Today is a' eeee");
datetime import { datetime } from "https://deno.land/x/ptera/mod.ts"; // now in
local time datetime(); datetime("2021-06-30T21:15:30.200"); // JavaScript Date datetime(new Date()); // Object datetime({ year: 2021, month: 3, day: 21 }); // Unixtime datetime(1625238137000); // Array datetime([2021, 6, 11, 13, 30, 30]);
Parse and Format const parsedDate = datetime().parse( "5/Aug/2021:14:15:30 +0900", "d/MMM/YYYY:HH:mm:ss
ZZ" ); // support locale datetime().parse("2021 лютий 03", "YYYY MMMM dd", { locale: "uk" }); // format to ISO 8601 const dt = datetime({ year: 2021, month: 7, day: 21, hour: 23, minute: 30, second: 59, }); dt.toISO(); // 2021-07-21T23:30:59.000Z dt.toISODate(); // 2021-07-21 dt.toISOWeekDateDate(); // 2021-W29-3 dt.toISOTime(); // 23:30:59.000 dt.format("YYYY/MMMM/dd"); // 2021/July/21 // support locale dt.setLocale("fr").format("YYYY/MMMM/dd"); // // 2021/juillet/21
Timezone and Intl Basic // Timezone const dt = datetime().toZonedTime("America/New_York");
dt.offsetHour(); // -4 dt.offsetMin(); // -240 const utc = dt.toUTC(); // Intl const dtFr = datetime("2021-07-03").setLocale("fr"); dtFr.toDateTimeFormat({ dateStyle: "full" }); // samedi 3 juillet 2021; datetime("2045-01-01").isBefore(); // false datetime("2045-01-01").isAfter(); // true datetime("2045-01-01").isAfter(datetime("2030-01-01")); // true datetime("2020-01-01").isLeapYear(); // true datetime("2021-13-01").isValid(); // false
Math import { diffInMillisec, latestDateTime, oldestDateTime, } from "https://deno.land/x/ptera/mod.ts"; const
dt1 = datetime("2021-08-21:13:30:00"); const dt2 = datetime("2021-01-30:21:30:00"); diffInMillisec(dt1, dt2); // 17510400000 const latest = datetime("2021-08-21"); const oldest = datetime("2021-01-30"); const middle = datetime("2021-04-30"); const datetimes = [latest, oldest, middle]; latestDateTime(datetimes); // latest oldestDateTime(datetimes); // oldest const dt = datetime("2021-08-21:13:30:00"); // { year: 2021, month: 8, day: 21, hour: 13, minute: 30, second: 0, millisecond: 0, } dt.add({ year: 1 }).substract({ month: 2 }); // { year: 2022, month: 6, day: 21, hour: 13, minute: 30, second: 0, millisecond: 0, }
今後について Temporal ECMAScript 標準の日付 API(2021 年 8 月現在、Stage3) Temporal API
が実装されれば Ptera を含めた、ラッパークラスを提供しているライブラリは不要になる? Temporal 版 date-fns のようなライブラリにできると面白そう const zonedDateTime = Temporal.ZonedDateTime.from({ timeZone: "America/Los_Angeles", year: 1995, month: 12, day: 7, }); const record = Temporal.Duration.from({ minutes: 26, seconds: 17, milliseconds: 530, });
Deno で日付を扱う際にぜひお試しください!