From 6d3f430b24f53f386d833b2275801cea16178b5b Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Wed, 22 Oct 2014 17:27:46 -0700 Subject: [PATCH 1/3] Fixed: constructor of CPDate can take string param Previously, when making a CPDate with some constructors, we could pass a string or nil to create a date. For example it was allowed to do var date = [CPDate dateWithTimeIntervalSince1970:"10"]; Now this is not possible anymore and it works like in Cocoa, only number are authorized. --- Foundation/CPDate.j | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Foundation/CPDate.j b/Foundation/CPDate.j index 736ca9ff2..62eebc25c 100644 --- a/Foundation/CPDate.j +++ b/Foundation/CPDate.j @@ -74,24 +74,36 @@ var CPDateReferenceDate = new Date(Date.UTC(2001, 0, 1, 0, 0, 0, 0)); - (id)initWithTimeIntervalSinceNow:(CPTimeInterval)seconds { + if (!_isNumberType(seconds)) + [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSinceNow: has to be an integer"]; + self = new Date((new Date()).getTime() + seconds * 1000); return self; } - (id)initWithTimeIntervalSince1970:(CPTimeInterval)seconds { + if (!_isNumberType(seconds)) + [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSince1970: has to be an integer"]; + self = new Date(seconds * 1000); return self; } - (id)initWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds { + if (!_isNumberType(seconds)) + [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSinceReferenceDate: has to be an integer"]; + self = [self initWithTimeInterval:seconds sinceDate:CPDateReferenceDate]; return self; } - (id)initWithTimeInterval:(CPTimeInterval)seconds sinceDate:(CPDate)refDate { + if (!_isNumberType(seconds)) + [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeInterval:sinceDate: has to be an integer"]; + self = new Date(refDate.getTime() + seconds * 1000); return self; } @@ -275,3 +287,11 @@ Date.parseISO8601 = function (date) }; Date.prototype.isa = CPDate; + +function _isNumberType(value) +{ + if (typeof value === 'number') + return YES; + else + return NO; +} \ No newline at end of file From d5e811f9f1ecef6d000ad664e96160a30ee5a9d8 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Sun, 26 Oct 2014 21:27:10 -0700 Subject: [PATCH 2/3] Fixed: exception descriptions in CPDate did not countain all of the needed informations --- Foundation/CPDate.j | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Foundation/CPDate.j b/Foundation/CPDate.j index 62eebc25c..47abdfe7d 100644 --- a/Foundation/CPDate.j +++ b/Foundation/CPDate.j @@ -75,7 +75,7 @@ var CPDateReferenceDate = new Date(Date.UTC(2001, 0, 1, 0, 0, 0, 0)); - (id)initWithTimeIntervalSinceNow:(CPTimeInterval)seconds { if (!_isNumberType(seconds)) - [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSinceNow: has to be an integer"]; + [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSinceNow: has to be an integer or a float"]; self = new Date((new Date()).getTime() + seconds * 1000); return self; @@ -84,7 +84,7 @@ var CPDateReferenceDate = new Date(Date.UTC(2001, 0, 1, 0, 0, 0, 0)); - (id)initWithTimeIntervalSince1970:(CPTimeInterval)seconds { if (!_isNumberType(seconds)) - [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSince1970: has to be an integer"]; + [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSince1970: has to be an integer or a float"]; self = new Date(seconds * 1000); return self; @@ -93,7 +93,7 @@ var CPDateReferenceDate = new Date(Date.UTC(2001, 0, 1, 0, 0, 0, 0)); - (id)initWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds { if (!_isNumberType(seconds)) - [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSinceReferenceDate: has to be an integer"]; + [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSinceReferenceDate: has to be an integer or a float"]; self = [self initWithTimeInterval:seconds sinceDate:CPDateReferenceDate]; return self; @@ -102,7 +102,7 @@ var CPDateReferenceDate = new Date(Date.UTC(2001, 0, 1, 0, 0, 0, 0)); - (id)initWithTimeInterval:(CPTimeInterval)seconds sinceDate:(CPDate)refDate { if (!_isNumberType(seconds)) - [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeInterval:sinceDate: has to be an integer"]; + [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeInterval:sinceDate: has to be an integer or a float"]; self = new Date(refDate.getTime() + seconds * 1000); return self; From fa7b71cabe851f4b19e0bf22fa8874d1320b55e8 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Fri, 9 Jan 2015 08:37:29 -0800 Subject: [PATCH 3/3] Fixed: cappuccino raised an exception when the param of constructor method of a CPDate are not a string. It now raises an warning --- Foundation/CPDate.j | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Foundation/CPDate.j b/Foundation/CPDate.j index 47abdfe7d..574873ef6 100644 --- a/Foundation/CPDate.j +++ b/Foundation/CPDate.j @@ -75,7 +75,7 @@ var CPDateReferenceDate = new Date(Date.UTC(2001, 0, 1, 0, 0, 0, 0)); - (id)initWithTimeIntervalSinceNow:(CPTimeInterval)seconds { if (!_isNumberType(seconds)) - [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSinceNow: has to be an integer or a float"]; + CPLog.warn(@"The parameter of the method initWithTimeIntervalSinceNow: should be an integer or a float"); self = new Date((new Date()).getTime() + seconds * 1000); return self; @@ -84,7 +84,7 @@ var CPDateReferenceDate = new Date(Date.UTC(2001, 0, 1, 0, 0, 0, 0)); - (id)initWithTimeIntervalSince1970:(CPTimeInterval)seconds { if (!_isNumberType(seconds)) - [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSince1970: has to be an integer or a float"]; + CPLog.warn(@"The parameter of the method initWithTimeIntervalSince1970: should be an integer or a float"); self = new Date(seconds * 1000); return self; @@ -93,7 +93,7 @@ var CPDateReferenceDate = new Date(Date.UTC(2001, 0, 1, 0, 0, 0, 0)); - (id)initWithTimeIntervalSinceReferenceDate:(CPTimeInterval)seconds { if (!_isNumberType(seconds)) - [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeIntervalSinceReferenceDate: has to be an integer or a float"]; + CPLog.warn(@"The parameter of the method initWithTimeIntervalSinceReferenceDate: should be an integer or a float"); self = [self initWithTimeInterval:seconds sinceDate:CPDateReferenceDate]; return self; @@ -102,7 +102,7 @@ var CPDateReferenceDate = new Date(Date.UTC(2001, 0, 1, 0, 0, 0, 0)); - (id)initWithTimeInterval:(CPTimeInterval)seconds sinceDate:(CPDate)refDate { if (!_isNumberType(seconds)) - [CPException raise:CPInvalidArgumentException reason:@"The parameter of the method initWithTimeInterval:sinceDate: has to be an integer or a float"]; + CPLog.warn(@"The parameter of the method initWithTimeInterval:sinceDate: should be an integer or a float"); self = new Date(refDate.getTime() + seconds * 1000); return self;