aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/date-fns/esm/_lib/format/lightFormatters
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/date-fns/esm/_lib/format/lightFormatters')
-rw-r--r--node_modules/date-fns/esm/_lib/format/lightFormatters/index.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/node_modules/date-fns/esm/_lib/format/lightFormatters/index.js b/node_modules/date-fns/esm/_lib/format/lightFormatters/index.js
new file mode 100644
index 0000000..98c9308
--- /dev/null
+++ b/node_modules/date-fns/esm/_lib/format/lightFormatters/index.js
@@ -0,0 +1,80 @@
+import addLeadingZeros from "../../addLeadingZeros/index.js";
+/*
+ * | | Unit | | Unit |
+ * |-----|--------------------------------|-----|--------------------------------|
+ * | a | AM, PM | A* | |
+ * | d | Day of month | D | |
+ * | h | Hour [1-12] | H | Hour [0-23] |
+ * | m | Minute | M | Month |
+ * | s | Second | S | Fraction of second |
+ * | y | Year (abs) | Y | |
+ *
+ * Letters marked by * are not implemented but reserved by Unicode standard.
+ */
+var formatters = {
+ // Year
+ y: function y(date, token) {
+ // From http://www.unicode.org/reports/tr35/tr35-31/tr35-dates.html#Date_Format_tokens
+ // | Year | y | yy | yyy | yyyy | yyyyy |
+ // |----------|-------|----|-------|-------|-------|
+ // | AD 1 | 1 | 01 | 001 | 0001 | 00001 |
+ // | AD 12 | 12 | 12 | 012 | 0012 | 00012 |
+ // | AD 123 | 123 | 23 | 123 | 0123 | 00123 |
+ // | AD 1234 | 1234 | 34 | 1234 | 1234 | 01234 |
+ // | AD 12345 | 12345 | 45 | 12345 | 12345 | 12345 |
+
+ var signedYear = date.getUTCFullYear();
+ // Returns 1 for 1 BC (which is year 0 in JavaScript)
+ var year = signedYear > 0 ? signedYear : 1 - signedYear;
+ return addLeadingZeros(token === 'yy' ? year % 100 : year, token.length);
+ },
+ // Month
+ M: function M(date, token) {
+ var month = date.getUTCMonth();
+ return token === 'M' ? String(month + 1) : addLeadingZeros(month + 1, 2);
+ },
+ // Day of the month
+ d: function d(date, token) {
+ return addLeadingZeros(date.getUTCDate(), token.length);
+ },
+ // AM or PM
+ a: function a(date, token) {
+ var dayPeriodEnumValue = date.getUTCHours() / 12 >= 1 ? 'pm' : 'am';
+ switch (token) {
+ case 'a':
+ case 'aa':
+ return dayPeriodEnumValue.toUpperCase();
+ case 'aaa':
+ return dayPeriodEnumValue;
+ case 'aaaaa':
+ return dayPeriodEnumValue[0];
+ case 'aaaa':
+ default:
+ return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.';
+ }
+ },
+ // Hour [1-12]
+ h: function h(date, token) {
+ return addLeadingZeros(date.getUTCHours() % 12 || 12, token.length);
+ },
+ // Hour [0-23]
+ H: function H(date, token) {
+ return addLeadingZeros(date.getUTCHours(), token.length);
+ },
+ // Minute
+ m: function m(date, token) {
+ return addLeadingZeros(date.getUTCMinutes(), token.length);
+ },
+ // Second
+ s: function s(date, token) {
+ return addLeadingZeros(date.getUTCSeconds(), token.length);
+ },
+ // Fraction of second
+ S: function S(date, token) {
+ var numberOfDigits = token.length;
+ var milliseconds = date.getUTCMilliseconds();
+ var fractionalSeconds = Math.floor(milliseconds * Math.pow(10, numberOfDigits - 3));
+ return addLeadingZeros(fractionalSeconds, token.length);
+ }
+};
+export default formatters; \ No newline at end of file
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage