<div class="cnblogs_code">
('use strict'</span><span style="color: #008000">/*</span><span style="color: #008000">*
* myApp Module
*
* Description
</span><span style="color: #008000">*/</span><span style="color: #000000">
angular.module(</span>'myApp'<span style="color: #000000">)
.filter(</span>'is_null',<span style="color: #0000ff">function</span><span style="color: #000000">() {
</span><span style="color: #0000ff">return</span> <span style="color: #0000ff">function</span><span style="color: #000000">(input) {
</span><span style="color: #0000ff">return</span> input || '/'<span style="color: #000000">;
}
})
.filter(</span>'star',<span style="color: #0000ff">function</span><span style="color: #000000">() {
</span><span style="color: #0000ff">return</span> <span style="color: #0000ff">function</span><span style="color: #000000">(input) {
</span><span style="color: #0000ff">return</span> Math.floor(input) || 0<span style="color: #000000">;
}
})
.filter(</span>'unstar',<span style="color: #0000ff">function</span><span style="color: #000000">() {
</span><span style="color: #0000ff">return</span> <span style="color: #0000ff">function</span><span style="color: #000000">(input) {
</span><span style="color: #0000ff">return</span> 5 - Math.ceil(input) || 0<span style="color: #000000">;
}
})
.filter(</span>'percent',<span style="color: #0000ff">function</span><span style="color: #000000">() {
</span><span style="color: #0000ff">return</span> <span style="color: #0000ff">function</span><span style="color: #000000">(input) {
</span><span style="color: #0000ff">return</span> (input * 100).toFixed(2) || 0<span style="color: #000000">;
}
})
</span><span style="color: #008000">//</span><span style="color: #008000"> 毫秒转天时分</span>
.filter('formatDuring',<span style="color: #0000ff">function</span><span style="color: #000000">() {
</span><span style="color: #0000ff">return</span> <span style="color: #0000ff">function</span><span style="color: #000000">(mss) {
</span><span style="color: #0000ff">var</span> days = parseInt(mss / (1000 * 60 * 60 * 24<span style="color: #000000">));
</span><span style="color: #0000ff">var</span> hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60<span style="color: #000000">));
</span><span style="color: #0000ff">var</span> minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60<span style="color: #000000">));
</span><span style="color: #0000ff">var</span> seconds = (mss % (1000 * 60)) / 1000<span style="color: #000000">;
</span><span style="color: #0000ff">return</span> days + " 天 " + hours + " 小时 " + minutes + " 分钟 " + seconds + " 秒 "<span style="color: #000000">;
}
})
</span><span style="color: #008000">//</span><span style="color: #008000">时间戳转换</span>
.filter('getWeek',<span style="color: #0000ff">function</span><span style="color: #000000">() {
</span><span style="color: #0000ff">return</span> <span style="color: #0000ff">function</span><span style="color: #000000">(input) {
</span><span style="color: #0000ff">var</span> date = <span style="color: #0000ff">new</span> Date(input * 1000<span style="color: #000000">);
</span><span style="color: #0000ff">var</span> week =<span style="color: #000000"> date.getDay();
</span><span style="color: #0000ff">switch</span><span style="color: #000000"> (week) {
</span><span style="color: #0000ff">case</span> 0<span style="color: #000000">:
</span><span style="color: #0000ff">return</span> "星期天"<span style="color: #000000">;
</span><span style="color: #0000ff">break</span><span style="color: #000000">;
</span><span style="color: #0000ff">case</span> 1<span style="color: #000000">:
</span><span style="color: #0000ff">return</span> "星期一"<span style="color: #000000">;
</span><span style="color: #0000ff">break</span><span style="color: #000000">;
</span><span style="color: #0000ff">case</span> 2<span style="color: #000000">:
</span><span style="color: #0000ff">return</span> "星期二"<span style="color: #000000">;
</span><span style="color: #0000ff">break</span><span style="color: #000000">;
</span><span style="color: #0000ff">case</span> 3<span style="color: #000000">:
</span><span style="color: #0000ff">return</span> "星期三"<span style="color: #000000">;
</span><span style="color: #0000ff">break</span><span style="color: #000000">;
</span><span style="color: #0000ff">case</span> 4<span style="color: #000000">:
</span><span style="color: #0000ff">return</span> "星期四"<span style="color: #000000">;
</span><span style="color: #0000ff">break</span><span style="color: #000000">;
</span><span style="color: #0000ff">case</span> 5<span style="color: #000000">:
</span><span style="color: #0000ff">return</span> "星期五"<span style="color: #000000">;
</span><span style="color: #0000ff">break</span><span style="color: #000000">;
</span><span style="color: #0000ff">case</span> 6<span style="color: #000000">:
</span><span style="color: #0000ff">return</span> "星期六"<span style="color: #000000">;
</span><span style="color: #0000ff">break</span><span style="color: #000000">;
}
}
})
.filter(</span>'snapshot',<span style="color: #0000ff">function</span><span style="color: #000000">() {
</span><span style="color: #0000ff">return</span> <span style="color: #0000ff">function</span><span style="color: #000000">(input) {
input </span>= input || ''<span style="color: #000000">;
</span><span style="color: #0000ff">var</span> output = input.split('|')[0<span style="color: #000000">];
</span><span style="color: #0000ff">return</span><span style="color: #000000"> output;
}
})
})();