Skip to content

Commit

Permalink
Merge pull request #155 from TalhaAwan/master
Browse files Browse the repository at this point in the history
change DDD abbreviation for yesterday, today and tomorrow
  • Loading branch information
chase-manning authored Dec 22, 2020
2 parents 111e2f2 + 4f1aba0 commit 4142ef1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ dateFormat(now, "N");
| `d` | Day of the month as digits; no leading zero for single-digit days. |
| `dd` | Day of the month as digits; leading zero for single-digit days. |
| `ddd` | Day of the week as a three-letter abbreviation. |
| `DDD` | "Yes", "Tod" or "Tom" if date lies within these three days. Else fall back to ddd. |
| `DDD` | "Ysd", "Tdy" or "Tmw" if date lies within these three days. Else fall back to ddd. |
| `dddd` | Day of the week as its full name. |
| `DDDD` | "Yesterday", "Today" or "Tomorrow" if date lies within these three days. Else fall back to dddd. |
| `m` | Month as digits; no leading zero for single-digit months. |
Expand Down
6 changes: 3 additions & 3 deletions src/dateformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@
const tomorrow_y = () => tomorrow[_ + 'FullYear']();

if (today_y() === y && today_m() === m && today_D() === D) {
return short ? 'Tod' : 'Today';
return short ? 'Tdy' : 'Today';
}
else if (yesterday_y() === y && yesterday_m() === m && yesterday_D() === D) {
return short ? 'Yes' : 'Yesterday';
return short ? 'Ysd' : 'Yesterday';
}
else if (tomorrow_y() === y && tomorrow_m() === m && tomorrow_D() === D) {
return short ? 'Tom' : 'Tomorrow';
return short ? 'Tmw' : 'Tomorrow';
}
return dayName;
};
Expand Down
18 changes: 9 additions & 9 deletions test/test_threedays.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const dateFormat = require('./../lib/dateformat');

const dayNamesShort = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const dayNamesLong = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const threeDays = ['Yesterday', 'Today', 'Tomorrow', 'Yes', 'Tod', 'Tom'];
const threeDays = ['Yesterday', 'Today', 'Tomorrow', 'Ysd', 'Tdy', 'Tmw'];

describe('threeDays', function () {
let date, DDD, DDDD;
Expand All @@ -17,20 +17,20 @@ describe('threeDays', function () {
assert.strictEqual(DDDD, "Yesterday");
done();
});
it('should return "Yes" (Today - 1 day)', function (done) {
it('should return "Ysd" (Today - 1 day)', function (done) {
date.setDate(date.getDate() - 1);
DDD = dateFormat(date, 'DDD');
assert.strictEqual(DDD, "Yes");
assert.strictEqual(DDD, "Ysd");
done();
});
it('should return "Today" (Today)', function (done) {
DDDD = dateFormat(date, 'DDDD');
assert.strictEqual(DDDD, "Today");
done();
});
it('should return "Tod" (Today)', function (done) {
it('should return "Tdy" (Today)', function (done) {
DDD = dateFormat(date, 'DDD');
assert.strictEqual(DDD, "Tod");
assert.strictEqual(DDD, "Tdy");
done();
});
it('should return "Tomorrow" (Today + 1 day)', function (done) {
Expand All @@ -39,21 +39,21 @@ describe('threeDays', function () {
assert.strictEqual(DDDD, "Tomorrow");
done();
});
it('should return "Tom" (Today + 1 day)', function (done) {
it('should return "Tmw" (Today + 1 day)', function (done) {
date.setDate(date.getDate() + 1);
DDD = dateFormat(date, 'DDD');
assert.strictEqual(DDD, "Tom");
assert.strictEqual(DDD, "Tmw");
done();
});
it('should not return "Yesterday", "Today", "Tomorrow", "Yes", "Tod", or "Tom" (Today - 2 days)', function (done) {
it('should not return "Yesterday", "Today", "Tomorrow", "Ysd", "Tdy", or "Tmw" (Today - 2 days)', function (done) {
date.setDate(date.getDate() - 2);
DDD = dateFormat(date, 'DDD');
DDDD = dateFormat(date, 'DDDD');
assert.strictEqual(threeDays.indexOf(DDD), -1);
assert.strictEqual(threeDays.indexOf(DDDD), -1);
done();
});
it('should not return "Yesterday", "Today" or "Tomorrow", "Yes", "Tod", or "Tom" (Today + 2 days)', function (done) {
it('should not return "Yesterday", "Today" or "Tomorrow", "Ysd", "Tdy", or "Tmw" (Today + 2 days)', function (done) {
date.setDate(date.getDate() + 2);
DDD = dateFormat(date, 'DDD');
DDDD = dateFormat(date, 'DDDD');
Expand Down

0 comments on commit 4142ef1

Please sign in to comment.