Created
February 8, 2012 16:50
-
-
Save timrwood/1771023 to your computer and use it in GitHub Desktop.
Moment calendar without time plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var oldcal = moment.calendar; | |
var newcal = { | |
sameDay : '[Today]', | |
nextDay : '[Tomorrow]', | |
nextWeek : 'dddd', | |
lastDay : '[Yesterday]', | |
lastWeek : '[last] dddd', | |
sameElse : 'L' | |
}; | |
moment.fn.oldcalendar = moment.fn.calendar; | |
moment.fn.calendar = function(withoutTime) { | |
if (withoutTime) { | |
moment.calendar = newcal; | |
} else { | |
moment.calendar = oldcal; | |
} | |
return this.oldcalendar(); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this approach doesn't work and return empty string "", if moment doesn't contain " at" this is all "sameElse" dates.
default:
moment().calendar(null, {
sameDay: '[Today]',
nextDay: '[Tomorrow]',
nextWeek: 'dddd',
lastDay: '[Yesterday]',
lastWeek: '[Last] dddd',
sameElse: 'DD/MM/YYYY'
});
+1 to the
(moment(time).calendar().split(" at"))[0]
thanks