summaryrefslogtreecommitdiff
path: root/date-fns/examples/typescript/fp.ts
diff options
context:
space:
mode:
Diffstat (limited to 'date-fns/examples/typescript/fp.ts')
-rw-r--r--date-fns/examples/typescript/fp.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/date-fns/examples/typescript/fp.ts b/date-fns/examples/typescript/fp.ts
new file mode 100644
index 0000000..79d6311
--- /dev/null
+++ b/date-fns/examples/typescript/fp.ts
@@ -0,0 +1,17 @@
+import { addYears, formatWithOptions } from 'date-fns/fp'
+import { eo } from 'date-fns/locale'
+
+const addFiveYears = addYears(5)
+const dateToString = formatWithOptions({ locale: eo }, 'd MMMM yyyy')
+
+const dates = [
+ new Date(2017, 0 /* Jan */, 1),
+ new Date(2017, 1 /* Feb */, 11),
+ new Date(2017, 6 /* Jul */, 2)
+]
+
+const formattedDates = dates
+ .map(date => dateToString(addFiveYears(date)))
+ .join(', ')
+
+console.log(formattedDates === '1 januaro 2022, 11 februaro 2022, 2 julio 2022')