Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 805753d

Browse files
committed
fixed issue where date copy creates an object instead of date
1 parent 3ab4953 commit 805753d

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

regression/resource_json_date.html

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE HTML>
2+
<html xmlns:ng="http://angularjs.org">
3+
<head>
4+
<script type="text/javascript" src="../src/angular-bootstrap.js" ng:autobind></script>
5+
</script>
6+
<script type="text/javascript">
7+
angular.service('myService', function($resource){
8+
this.myData = $resource('resource_json_date.json');
9+
}, {$inject:['$resource'], $creation:'eager'});
10+
11+
/* The Controller object */
12+
MyController = function() {
13+
this.inlineData = angular.fromJson('{reportDate:"2010-10-13T17:37:00Z"}');
14+
this.jsonData = this.myData.get();
15+
};
16+
17+
18+
19+
</script>
20+
</head>
21+
<body ng:controller="MyController" ng:init="$window.$root = this">
22+
<h3>This data is loaded with angular.fromJson:</h3>
23+
{{ inlineData.reportDate | date }}
24+
<hr/>
25+
<h3>This data is loaded from a resource using a service:</h3>
26+
<p>Name: {{ jsonData.name }}</p>
27+
<p>Parsed date: {{ jsonData.reportDate }} (A date should be displayed here)</p>
28+
29+
</body>
30+
</html>

regression/resource_json_date.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{reportDate:"2010-10-13T17:37:00Z", name:"camilo"}

src/Angular.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,16 @@ function isLeafNode (node) {
226226
*/
227227
function copy(source, destination){
228228
if (!destination) {
229+
destination = source;
229230
if (source) {
230231
if (isArray(source)) {
231-
return copy(source, []);
232+
destination = copy(source, []);
233+
} else if (source instanceof Date) {
234+
destination = new Date(source.getTime());
232235
} else if (isObject(source)) {
233-
return copy(source, {});
236+
destination = copy(source, {});
234237
}
235238
}
236-
return source;
237239
} else {
238240
if (isArray(source)) {
239241
while(destination.length) {
@@ -250,8 +252,8 @@ function copy(source, destination){
250252
destination[key] = copy(source[key]);
251253
}
252254
}
253-
return destination;
254255
}
256+
return destination;
255257
}
256258

257259
function equals(o1, o2) {

test/AngularSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ describe("copy", function(){
2121
assertSame(arr, copy([], arr));
2222
});
2323

24+
it("should copy Date", function(){
25+
var date = new Date(123);
26+
expect(copy(date) instanceof Date).toBeTruthy();
27+
expect(copy(date).getTime()).toEqual(123);
28+
expect(copy(date) === date).toBeFalsy();
29+
});
30+
2431
it("should copy array", function(){
2532
var src = [1, {name:"value"}];
2633
var dst = [{key:"v"}];

0 commit comments

Comments
 (0)