Skip to content
This repository was archived by the owner on Sep 15, 2020. It is now read-only.

Commit 3db1190

Browse files
committed
Add t/T format
closes #2
1 parent f022ae8 commit 3db1190

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+309
-214
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ Format Options
7979
- ff: Hundredths of a second
8080
- fff: Thousandths of a second
8181
- tt: am/pm
82+
- t: a/p
8283
- TT: AM/PM
84+
- T: A/P
8385
- zzzz: timezone (e.g. -05:00)
8486
- zzz: timezone (e.g. -5:00)
8587
- zz: timezone (e.g. -05)

js-date-format.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ <h4>Options</h4>
5959
<li>ff: Hundredths of a second = <script type="text/javascript">document.write((new Date).format("ff"));</script></li>
6060
<li>fff: Thousandths of a second = <script type="text/javascript">document.write((new Date).format("fff"));</script></li>
6161
<li>tt: am/pm = <script type="text/javascript">document.write((new Date).format("tt"));</script></li>
62+
<li>t: a/p = <script type="text/javascript">document.write((new Date).format("t"));</script></li>
6263
<li>TT: AM/PM = <script type="text/javascript">document.write((new Date).format("TT"));</script></li>
64+
<li>T: A/P = <script type="text/javascript">document.write((new Date).format("T"));</script></li>
6365
<li>zzzz: timezone = <script type="text/javascript">document.write((new Date).format("zzzz"));</script></li>
6466
<li>zzz: timezone = <script type="text/javascript">document.write((new Date).format("zzz"));</script></li>
6567
<li>zz: timezone = <script type="text/javascript">document.write((new Date).format("zz"));</script></li>

js-date-format.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
return "th";
3333
}
3434
},
35-
meridiem: function (hour, minute, isLower) {
36-
if (hour < 12) {
37-
return isLower ? "am" : "AM";
38-
} else {
39-
return isLower ? "pm" : "PM";
40-
}
35+
meridiem: function (hour, minute, isLower, isShort) {
36+
var m = (hour < 12 ? "AM" : "PM");
37+
m = (isLower ? m.toLowerCase() : m);
38+
m = (isShort ? m[0] : m);
39+
40+
return m;
4141
}
4242
}
4343
};
@@ -108,14 +108,14 @@
108108
return Date.locales[locale].date_suffix(this.getDate());
109109
};
110110

111-
Date.prototype.getMeridiem = function (isLower, lang) {
111+
Date.prototype.getMeridiem = function (isLower, isShort, lang) {
112112
var locale = "en";
113113
if (lang && lang in Date.locales) {
114114
locale = lang;
115115
} else if (this.locale && this.locale in Date.locales) {
116116
locale = this.locale;
117117
}
118-
return Date.locales[locale].meridiem(this.getHours(), this.getMinutes(), isLower);
118+
return Date.locales[locale].meridiem(this.getHours(), this.getMinutes(), isLower, isShort);
119119
};
120120

121121
Date.prototype.getLastDate = function () {
@@ -226,10 +226,16 @@
226226
return Math.floor(-this.date.getTimezoneOffset() / 60);
227227
},
228228
tt: function () {
229-
return this.date.getMeridiem(true);
229+
return this.date.getMeridiem(true, false);
230+
},
231+
t: function () {
232+
return this.date.getMeridiem(true, true);
230233
},
231234
TT: function () {
232-
return this.date.getMeridiem(false);
235+
return this.date.getMeridiem(false, false);
236+
},
237+
T: function () {
238+
return this.date.getMeridiem(false, true);
233239
}
234240
};
235241

js-date-format.min.js

Lines changed: 1 addition & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)