mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-23 05:25:47 +00:00
fixed issue where date copy creates an object instead of date
This commit is contained in:
parent
3ab49538a4
commit
805753dba4
4 changed files with 44 additions and 4 deletions
30
regression/resource_json_date.html
Normal file
30
regression/resource_json_date.html
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html xmlns:ng="http://angularjs.org">
|
||||||
|
<head>
|
||||||
|
<script type="text/javascript" src="../src/angular-bootstrap.js" ng:autobind></script>
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
angular.service('myService', function($resource){
|
||||||
|
this.myData = $resource('resource_json_date.json');
|
||||||
|
}, {$inject:['$resource'], $creation:'eager'});
|
||||||
|
|
||||||
|
/* The Controller object */
|
||||||
|
MyController = function() {
|
||||||
|
this.inlineData = angular.fromJson('{reportDate:"2010-10-13T17:37:00Z"}');
|
||||||
|
this.jsonData = this.myData.get();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body ng:controller="MyController" ng:init="$window.$root = this">
|
||||||
|
<h3>This data is loaded with angular.fromJson:</h3>
|
||||||
|
{{ inlineData.reportDate | date }}
|
||||||
|
<hr/>
|
||||||
|
<h3>This data is loaded from a resource using a service:</h3>
|
||||||
|
<p>Name: {{ jsonData.name }}</p>
|
||||||
|
<p>Parsed date: {{ jsonData.reportDate }} (A date should be displayed here)</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1
regression/resource_json_date.json
Normal file
1
regression/resource_json_date.json
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{reportDate:"2010-10-13T17:37:00Z", name:"camilo"}
|
||||||
|
|
@ -226,14 +226,16 @@ function isLeafNode (node) {
|
||||||
*/
|
*/
|
||||||
function copy(source, destination){
|
function copy(source, destination){
|
||||||
if (!destination) {
|
if (!destination) {
|
||||||
|
destination = source;
|
||||||
if (source) {
|
if (source) {
|
||||||
if (isArray(source)) {
|
if (isArray(source)) {
|
||||||
return copy(source, []);
|
destination = copy(source, []);
|
||||||
|
} else if (source instanceof Date) {
|
||||||
|
destination = new Date(source.getTime());
|
||||||
} else if (isObject(source)) {
|
} else if (isObject(source)) {
|
||||||
return copy(source, {});
|
destination = copy(source, {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return source;
|
|
||||||
} else {
|
} else {
|
||||||
if (isArray(source)) {
|
if (isArray(source)) {
|
||||||
while(destination.length) {
|
while(destination.length) {
|
||||||
|
|
@ -250,8 +252,8 @@ function copy(source, destination){
|
||||||
destination[key] = copy(source[key]);
|
destination[key] = copy(source[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return destination;
|
|
||||||
}
|
}
|
||||||
|
return destination;
|
||||||
}
|
}
|
||||||
|
|
||||||
function equals(o1, o2) {
|
function equals(o1, o2) {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,13 @@ describe("copy", function(){
|
||||||
assertSame(arr, copy([], arr));
|
assertSame(arr, copy([], arr));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should copy Date", function(){
|
||||||
|
var date = new Date(123);
|
||||||
|
expect(copy(date) instanceof Date).toBeTruthy();
|
||||||
|
expect(copy(date).getTime()).toEqual(123);
|
||||||
|
expect(copy(date) === date).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
it("should copy array", function(){
|
it("should copy array", function(){
|
||||||
var src = [1, {name:"value"}];
|
var src = [1, {name:"value"}];
|
||||||
var dst = [{key:"v"}];
|
var dst = [{key:"v"}];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue