1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /**
- * Created by robin on 12/29/16.
- */
-
- (function () {
- 'use strict';
-
- angular.module('appSdk')
- .factory('DateUtilsBusiness', [
- function() {
-
- var DateUtilsBusiness = {};
- var dateFormat = 'DD MMM YYYY'; //TODO
- var timeFormat = 'HH[h]mm'; //TODO
- var dateTimeFormat = dateFormat + ' ' + timeFormat; //TODO
-
- DateUtilsBusiness.areSameDates = function(date1, date2)
- {
- if (date1 == null || date2 == null) {
- return date1 == date2;
- }
- return date1.getTime() == date2.getTime();
- };
-
- DateUtilsBusiness.format = function (date, format) {
- if (date == null) {
- return null;
- }
- return moment(date).format(format);
- };
-
- DateUtilsBusiness.formatDate = function(date)
- {
- return DateUtilsBusiness.format(date, dateFormat);
- };
-
- DateUtilsBusiness.formatTime = function(date)
- {
- return DateUtilsBusiness.format(date, timeFormat);
- };
-
- DateUtilsBusiness.formatDateTime = function(date)
- {
- return DateUtilsBusiness.format(date, dateTimeFormat);
- };
-
- DateUtilsBusiness.parse = function(date, format, strict)
- {
- if (date == null) {
- return null;
- }
- if (strict == null) {
- strict = true;
- }
- var d = moment(date, format, strict);
- if (d.isValid()) {
- return d.toDate();
- }
- return null;
- };
-
- DateUtilsBusiness.parseDate = function(date, strict)
- {
- return DateUtilsBusiness.parse(date, dateFormat, strict);
- };
-
- DateUtilsBusiness.parseTime = function(date, strict)
- {
- return DateUtilsBusiness.parse(date, timeFormat, strict);
- };
-
- DateUtilsBusiness.parseDateTime = function(date, strict)
- {
- return DateUtilsBusiness.parse(date, dateTimeFormat, strict);
- };
-
-
- return DateUtilsBusiness;
- }]);
- })();
|