Last active
August 29, 2015 14:23
-
-
Save benjamincharity/02e5b87f928d38266902 to your computer and use it in GitHub Desktop.
A filter that turns an array of integers into weekday names.
This file contains 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
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