Skip to content

Instantly share code, notes, and snippets.

@benjamincharity
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjamincharity/02e5b87f928d38266902 to your computer and use it in GitHub Desktop.
Save benjamincharity/02e5b87f928d38266902 to your computer and use it in GitHub Desktop.
A filter that turns an array of integers into weekday names.
angular.module('myModule')
.filter('weekdays', function() {
'use strict';
return function(day, length) {
// If length exists but doesn't match our keywords
if( length && length !== 'long' && length !== 'short' && length !== 'letter' ) {
return 'Length must be \'long\', \'short\' or \'letter\'';
}
var weekdays = {};
weekdays.long = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
weekdays.short = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
weekdays.letter = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
if( length === 'long' ) {
return weekdays.long[day];
}
if( length === 'short' || !length ) {
return weekdays.short[day];
}
if( length === 'letter' ) {
return weekdays.letter[day];
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment