Browse Source

added date manipulation functions; tests

tags/v0.2.2
Robin Thoni 7 years ago
parent
commit
4ae9b5c323

+ 35
- 0
src/Business/lu-utils-business.js View File

@@ -0,0 +1,35 @@
1
+/**
2
+ * Created by robin on 12/11/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticate2Utils')
8
+        .factory('luUtilsBusiness', ['luUtilsDataAccess', function (luUtilsDataAccess) {
9
+
10
+            var luUtilsBusiness = {};
11
+
12
+            luUtilsBusiness.momentDateTimeToString = function(date)
13
+            {
14
+                return luUtilsDataAccess.momentDateTimeToString(date);
15
+            };
16
+
17
+            luUtilsBusiness.stringToMomentDateTime = function(str)
18
+            {
19
+                return luUtilsDataAccess.stringToMomentDateTime(str);
20
+            };
21
+
22
+            luUtilsBusiness.dateTimeToString = function(date)
23
+            {
24
+                return luUtilsDataAccess.dateTimeToString(date);
25
+            };
26
+
27
+            luUtilsBusiness.stringToDateTime = function(str)
28
+            {
29
+                return luUtilsDataAccess.stringToDateTime(str);
30
+            };
31
+
32
+            return luUtilsBusiness;
33
+
34
+        }]);
35
+})();

+ 50
- 0
src/DataAccess/lu-utils-dataaccess.js View File

@@ -0,0 +1,50 @@
1
+/**
2
+ * Created by robin on 12/11/16.
3
+ */
4
+
5
+(function () {
6
+    'use strict';
7
+    angular.module('luticate2Utils')
8
+        .factory('luUtilsDataAccess', [function () {
9
+
10
+            var luUtilsDataAccess = {};
11
+
12
+            luUtilsDataAccess.momentDateTimeToString = function(date)
13
+            {
14
+                if (date == null) {
15
+                    return null;
16
+                }
17
+                return date.toISOString();
18
+            };
19
+
20
+            luUtilsDataAccess.stringToMomentDateTime = function(str)
21
+            {
22
+                if (str == null) {
23
+                    return null;
24
+                }
25
+                return new Date(str);
26
+            };
27
+
28
+            luUtilsDataAccess.dateTimeToString = function(date)
29
+            {
30
+                if (date == null) {
31
+                    return null;
32
+                }
33
+                var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds())).toISOString();
34
+                return d;
35
+            };
36
+
37
+            luUtilsDataAccess.stringToDateTime = function(str)
38
+            {
39
+                if (str == null) {
40
+                    return null;
41
+                }
42
+                var date = new Date(str);
43
+                var d = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());
44
+                return d;
45
+            };
46
+
47
+            return luUtilsDataAccess;
48
+
49
+        }]);
50
+})();

+ 11
- 12
src/DataAccess/lu-webapi-crud-dataaccess.js View File

@@ -5,7 +5,8 @@
5 5
 (function () {
6 6
     'use strict';
7 7
     angular.module('luticate2Utils')
8
-        .factory('luWebApiCrudDataAccess', ['luWebApiDataAccess', '$q', function (luWebApiDataAccess, $q) {
8
+        .factory('luWebApiCrudDataAccess', ['luWebApiDataAccess', '$q', 'luUtilsDataAccess',
9
+            function (luWebApiDataAccess, $q, luUtilsDataAccess) {
9 10
 
10 11
             var luWebApiCrudDataAccess = {};
11 12
 
@@ -84,6 +85,8 @@
84 85
 
85 86
                 DataAccess.defaultDbo = {
86 87
                     id: null,
88
+                    createdAt: null,
89
+                    updatedAt: null,
87 90
                     toString: function()
88 91
                     {
89 92
                         return this.id;
@@ -105,24 +108,20 @@
105 108
                     return dst;
106 109
                 };
107 110
 
108
-                DataAccess._initDbo = function(dbo)
111
+                DataAccess._initDbo = function(model)
109 112
                 {
110
-                    if (dbo == null) {
113
+                    if (model == null) {
111 114
                         return null;
112 115
                     }
113
-                    dbo = DataAccess.extendDeep({}, DataAccess.defaultDbo, dbo);
114
-                    if (dbo.createdAt != null) {
115
-                        dbo.createdAt = new Date(dbo.createdAt);
116
-                    }
117
-                    if (dbo.updatedAt != null) {
118
-                        dbo.updatedAt = new Date(dbo.updatedAt);
119
-                    }
116
+                    var dbo = DataAccess.extendDeep({}, DataAccess.defaultDbo, model);
117
+                    dbo.createdAt = luUtilsDataAccess.stringToMomentDateTime(dbo.createdAt);
118
+                    dbo.updatedAt = luUtilsDataAccess.stringToMomentDateTime(dbo.updatedAt);
120 119
                     return dbo;
121 120
                 };
122 121
 
123
-                DataAccess.initDbo = function(dbo)
122
+                DataAccess.initDbo = function(model)
124 123
                 {
125
-                    return DataAccess._initDbo(dbo);
124
+                    return DataAccess._initDbo(model);
126 125
                 };
127 126
 
128 127
                 DataAccess.initListDbo = function(list)

+ 6
- 2
tests/DataAccess/lu-webapi-crud-dataaccess-model.spec.js View File

@@ -83,7 +83,9 @@ describe('lu-webapi-crud-dataAccess dbo factory', function() {
83 83
                     someText: "42",
84 84
                     someInt: 42
85 85
                 },
86
-                url: '/api/entities/'
86
+                url: '/api/entities/',
87
+                createdAt: null,
88
+                updatedAt: null
87 89
             });
88 90
         }, function (error) {
89 91
             expect(error).toBeNull();
@@ -114,7 +116,9 @@ describe('lu-webapi-crud-dataAccess dbo factory', function() {
114 116
                     someText: "42",
115 117
                     someInt: 42
116 118
                 },
117
-                url: '/api/entities/xxx-x-x-x-xxx'
119
+                url: '/api/entities/xxx-x-x-x-xxx',
120
+                createdAt: null,
121
+                updatedAt: null
118 122
             });
119 123
         }, function (error) {
120 124
             expect(error).toBeNull();

Loading…
Cancel
Save