Mercurial > projects > dstep
diff dstep/foundation/NSDate.d @ 14:89f3c3ef1fd2
Added the Foundation framework
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:23:15 +0200 |
parents | |
children | 19885b43130e |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dstep/foundation/NSDate.d Mon Aug 03 15:23:15 2009 +0200 @@ -0,0 +1,205 @@ +/** + * Copyright: Copyright (c) 2009 Jacob Carlborg. + * Authors: Jacob Carlborg + * Version: Initial created: Aug 3, 2009 + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) + */ +module dstep.foundation.NSDate; + +import dstep.foundation.NSObject; +import dstep.foundation.NSString; +import dstep.objc.bridge.Bridge; +import dstep.objc.objc : id; + +alias double NSTimeInterval; + +class NSDate : NSObject, INSCopying, INSCoding +{ + mixin ObjcWrap; + mixin TNSExtendedDate; + mixin TNSDateCreation; + mixin TNSNaturalLangage; + mixin TNSCalendarDateExtras; + + double timeIntervalSinceReferenceDate () + { + return invokeObjcSelf!(double, "timeIntervalSinceReferenceDate"); + } + + Object copyWithZone (NSZone* zone) + { + return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); + } + + void encodeWithCoder (NSCoder aCoder) + { + return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); + } + + Object initWithCoder (NSCoder aDecoder) + { + return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); + } + + this (NSCoder aDecoder) + { + objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); + id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); + + if (result) + objcObject = ret; + + dObject = this; + } +} + +template TNSExtendedDate () +{ + double timeIntervalSinceDate (NSDate anotherDate) + { + return invokeObjcSelf!(double, "timeIntervalSinceDate:", NSDate)(anotherDate); + } + + double timeIntervalSinceNow () + { + return invokeObjcSelf!(double, "timeIntervalSinceNow"); + } + + double timeIntervalSince1970 () + { + return invokeObjcSelf!(double, "timeIntervalSince1970"); + } + + Object addTimeInterval (double seconds) + { + return invokeObjcSelf!(Object, "addTimeInterval:", double)(seconds); + } + + NSDate earlierDate (NSDate anotherDate) + { + return invokeObjcSelf!(NSDate, "earlierDate:", NSDate)(anotherDate); + } + + NSDate laterDate (NSDate anotherDate) + { + return invokeObjcSelf!(NSDate, "laterDate:", NSDate)(anotherDate); + } + + int compare (NSDate other) + { + return invokeObjcSelf!(int, "compare:", NSDate)(other); + } + + NSString description () + { + return invokeObjcSelf!(NSString, "description"); + } + + bool isEqualToDate (NSDate otherDate) + { + return invokeObjcSelf!(bool, "isEqualToDate:", NSDate)(otherDate); + } + + static double timeIntervalSinceReferenceDate () + { + return invokeObjcSelfClass!(double, "timeIntervalSinceReferenceDate"); + } +} + +template TNSDateCreation () +{ + static Object date () + { + return invokeObjcSelfClass!(Object, "date"); + } + + static Object dateWithTimeIntervalSinceNow (double secs) + { + return invokeObjcSelfClass!(Object, "dateWithTimeIntervalSinceNow:", double)(secs); + } + + static Object dateWithTimeIntervalSinceReferenceDate (double secs) + { + return invokeObjcSelfClass!(Object, "dateWithTimeIntervalSinceReferenceDate:", double)(secs); + } + + static Object dateWithTimeIntervalSince1970 (double secs) + { + return invokeObjcSelfClass!(Object, "dateWithTimeIntervalSince1970:", double)(secs); + } + + static Object distantFuture () + { + return invokeObjcSelfClass!(Object, "distantFuture"); + } + + static Object distantPast () + { + return invokeObjcSelfClass!(Object, "distantPast"); + } + + Object init () + { + return invokeObjcSelf!(Object, "init"); + } + + this () + { + objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); + id result = Bridge.invokeObjcMethod!(id, "init")(objcObject); + + if (result) + objcObject = ret; + + dObject = this; + } + + Object initWithTimeIntervalSinceReferenceDate (double secsToBeAdded) + { + return invokeObjcSelf!(Object, "initWithTimeIntervalSinceReferenceDate:", double)(secsToBeAdded); + } + + this (double secsToBeAdded) + { + objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); + id result = Bridge.invokeObjcMethod!(id, "initWithTimeIntervalSinceReferenceDate:", double)(objcObject, secsToBeAdded); + + if (result) + objcObject = ret; + + dObject = this; + } + + Object initWithTimeInterval (double secsToBeAdded, NSDate anotherDate) + { + return invokeObjcSelf!(Object, "initWithTimeInterval:sinceDate:", double, NSDate)(secsToBeAdded, anotherDate); + } + + this (double secsToBeAdded, NSDate anotherDate) + { + objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); + id result = Bridge.invokeObjcMethod!(id, "initWithTimeInterval:sinceDate:", double, NSDate)(objcObject, secsToBeAdded, anotherDate); + + if (result) + objcObject = ret; + + dObject = this; + } + + Object initWithTimeIntervalSinceNow (double secsToBeAddedToNow) + { + return invokeObjcSelf!(Object, "initWithTimeIntervalSinceNow:", double)(secsToBeAddedToNow); + } + + this (double secsToBeAddedToNow) + { + objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); + id result = Bridge.invokeObjcMethod!(id, "initWithTimeIntervalSinceNow:", double)(objcObject, secsToBeAddedToNow); + + if (result) + objcObject = ret; + + dObject = this; + } +} +