forked from mgcrea/angular-strap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate-formatter.js
More file actions
44 lines (43 loc) · 1.43 KB
/
date-formatter.js
File metadata and controls
44 lines (43 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* angular-strap
* @version v2.2.4 - 2015-05-28
* @link http://mgcrea.github.io/angular-strap
* @author Olivier Louvignes <olivier@mg-crea.com> (https://github.com/mgcrea)
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
'use strict';
angular.module('mgcrea.ngStrap.helpers.dateFormatter', []).service('$dateFormatter', [ '$locale', 'dateFilter', function($locale, dateFilter) {
this.getDefaultLocale = function() {
return $locale.id;
};
this.getDatetimeFormat = function(format, lang) {
return $locale.DATETIME_FORMATS[format] || format;
};
this.weekdaysShort = function(lang) {
return $locale.DATETIME_FORMATS.SHORTDAY;
};
function splitTimeFormat(format) {
return /(h+)([:\.])?(m+)([:\.])?(s*)[ ]?(a?)/i.exec(format).slice(1);
}
this.hoursFormat = function(timeFormat) {
return splitTimeFormat(timeFormat)[0];
};
this.minutesFormat = function(timeFormat) {
return splitTimeFormat(timeFormat)[2];
};
this.secondsFormat = function(timeFormat) {
return splitTimeFormat(timeFormat)[4];
};
this.timeSeparator = function(timeFormat) {
return splitTimeFormat(timeFormat)[1];
};
this.showSeconds = function(timeFormat) {
return !!splitTimeFormat(timeFormat)[4];
};
this.showAM = function(timeFormat) {
return !!splitTimeFormat(timeFormat)[5];
};
this.formatDate = function(date, format, lang, timezone) {
return dateFilter(date, format, timezone);
};
} ]);