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

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

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
 (function () {
5
 (function () {
6
     'use strict';
6
     'use strict';
7
     angular.module('luticate2Utils')
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
             var luWebApiCrudDataAccess = {};
11
             var luWebApiCrudDataAccess = {};
11
 
12
 
84
 
85
 
85
                 DataAccess.defaultDbo = {
86
                 DataAccess.defaultDbo = {
86
                     id: null,
87
                     id: null,
88
+                    createdAt: null,
89
+                    updatedAt: null,
87
                     toString: function()
90
                     toString: function()
88
                     {
91
                     {
89
                         return this.id;
92
                         return this.id;
105
                     return dst;
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
                         return null;
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
                     return dbo;
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
                 DataAccess.initListDbo = function(list)
127
                 DataAccess.initListDbo = function(list)

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

83
                     someText: "42",
83
                     someText: "42",
84
                     someInt: 42
84
                     someInt: 42
85
                 },
85
                 },
86
-                url: '/api/entities/'
86
+                url: '/api/entities/',
87
+                createdAt: null,
88
+                updatedAt: null
87
             });
89
             });
88
         }, function (error) {
90
         }, function (error) {
89
             expect(error).toBeNull();
91
             expect(error).toBeNull();
114
                     someText: "42",
116
                     someText: "42",
115
                     someInt: 42
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
         }, function (error) {
123
         }, function (error) {
120
             expect(error).toBeNull();
124
             expect(error).toBeNull();

Loading…
Cancel
Save