Mercurial > projects > dwt-mac
diff dwt/internal/cocoa/NSDate.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | 8b48be5454ce |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/internal/cocoa/NSDate.d Sat Aug 09 17:00:02 2008 +0200 @@ -0,0 +1,197 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * + * Port to the D Programming language: + * Jacob Carlborg <jacob.carlborg@gmail.com> + *******************************************************************************/ +module dwt.internal.cocoa.NSDate; + +import dwt.internal.cocoa.id; +import dwt.internal.cocoa.NSCalendarDate; +import dwt.internal.cocoa.NSObject; +import dwt.internal.cocoa.NSString; +import dwt.internal.cocoa.NSTimeZone; +import dwt.internal.cocoa.OS; +import objc = dwt.internal.objc.runtime; + +alias double NSTimeInterval; + +public class NSDate : NSObject +{ + public this () + { + super(); + } + + public this (objc.id id) + { + super(id); + } + + public id addTimeInterval (double seconds) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_addTimeInterval_1, seconds); + return result !is null ? new id(result) : null; + } + + public objc.id compare (NSDate other) + { + return OS.objc_msgSend(this.id, OS.sel_compare_1, other !is null ? other.id : null); + } + + public static NSDate date () + { + objc.id result = OS.objc_msgSend(OS.class_NSDate, OS.sel_date); + return result !is null ? new NSDate(result) : null; + } + + public NSCalendarDate dateWithCalendarFormat (NSString format, NSTimeZone aTimeZone) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_dateWithCalendarFormat_1timeZone_1, format !is null ? format.id : null, + aTimeZone !is null ? aTimeZone.id : null); + return result !is null ? new NSCalendarDate(result) : null; + } + + public static id static_dateWithNaturalLanguageString_ (NSString string) + { + objc.id result = OS.objc_msgSend(OS.class_NSDate, OS.sel_dateWithNaturalLanguageString_1, string !is null ? string.id : null); + return result !is null ? new id(result) : null; + } + + public static id static_dateWithNaturalLanguageString_locale_ (NSString string, id locale) + { + objc.id result = OS.objc_msgSend(OS.class_NSDate, OS.sel_dateWithNaturalLanguageString_1locale_1, string !is null ? string.id : null, + locale !is null ? locale.id : null); + return result !is null ? new id(result) : null; + } + + public static id dateWithString (NSString aString) + { + objc.id result = OS.objc_msgSend(OS.class_NSDate, OS.sel_dateWithString_1, aString !is null ? aString.id : null); + return result !is null ? new id(result) : null; + } + + public static id dateWithTimeIntervalSince1970 (double secs) + { + objc.id result = OS.objc_msgSend(OS.class_NSDate, OS.sel_dateWithTimeIntervalSince1970_1, secs); + return result !is null ? new id(result) : null; + } + + public static NSDate dateWithTimeIntervalSinceNow (double secs) + { + objc.id result = OS.objc_msgSend(OS.class_NSDate, OS.sel_dateWithTimeIntervalSinceNow_1, secs); + return result !is null ? new NSDate(result) : null; + } + + public static id dateWithTimeIntervalSinceReferenceDate (double secs) + { + objc.id result = OS.objc_msgSend(OS.class_NSDate, OS.sel_dateWithTimeIntervalSinceReferenceDate_1, secs); + return result !is null ? new id(result) : null; + } + + public NSString description () + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_description); + return result !is null ? new NSString(result) : null; + } + + public NSString descriptionWithCalendarFormat (NSString format, NSTimeZone aTimeZone, id locale) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_descriptionWithCalendarFormat_1timeZone_1locale_1, format !is null ? format.id : null, + aTimeZone !is null ? aTimeZone.id : null, locale !is null ? locale.id : null); + return result !is null ? new NSString(result) : null; + } + + public NSString descriptionWithLocale (id locale) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_descriptionWithLocale_1, locale !is null ? locale.id : null); + return result !is null ? new NSString(result) : null; + } + + public static NSDate distantFuture () + { + objc.id result = OS.objc_msgSend(OS.class_NSDate, OS.sel_distantFuture); + return result !is null ? new NSDate(result) : null; + } + + public static NSDate distantPast () + { + objc.id result = OS.objc_msgSend(OS.class_NSDate, OS.sel_distantPast); + return result !is null ? new NSDate(result) : null; + } + + public NSDate earlierDate (NSDate anotherDate) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_earlierDate_1, anotherDate !is null ? anotherDate.id : null); + return result is this.id ? this : (result !is null ? new NSDate(result) : null); + } + + public NSDate initWithString (NSString description) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_initWithString_1, description !is null ? description.id : null); + return result !is null ? this : null; + } + + public NSDate initWithTimeInterval (double secsToBeAdded, NSDate anotherDate) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_initWithTimeInterval_1sinceDate_1, secsToBeAdded, + anotherDate !is null ? anotherDate.id : null); + return result !is null ? this : null; + } + + public NSDate initWithTimeIntervalSinceNow (double secsToBeAddedToNow) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_initWithTimeIntervalSinceNow_1, secsToBeAddedToNow); + return result !is null ? this : null; + } + + public NSDate initWithTimeIntervalSinceReferenceDate (double secsToBeAdded) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_initWithTimeIntervalSinceReferenceDate_1, secsToBeAdded); + return result !is null ? this : null; + } + + public bool isEqualToDate (NSDate otherDate) + { + return OS.objc_msgSend(this.id, OS.sel_isEqualToDate_1, otherDate !is null ? otherDate.id : null) !is null; + } + + public NSDate laterDate (NSDate anotherDate) + { + objc.id result = OS.objc_msgSend(this.id, OS.sel_laterDate_1, anotherDate !is null ? anotherDate.id : null); + return result is this.id ? this : (result !is null ? new NSDate(result) : null); + } + + public double timeIntervalSince1970 () + { + return OS.objc_msgSend_fpret(this.id, OS.sel_timeIntervalSince1970); + } + + public double timeIntervalSinceDate (NSDate anotherDate) + { + return OS.objc_msgSend_fpret(this.id, OS.sel_timeIntervalSinceDate_1, anotherDate !is null ? anotherDate.id : null); + } + + public double timeIntervalSinceNow () + { + return OS.objc_msgSend_fpret(this.id, OS.sel_timeIntervalSinceNow); + } + + public static double static_timeIntervalSinceReferenceDate () + { + return OS.objc_msgSend_fpret(OS.class_NSDate, OS.sel_timeIntervalSinceReferenceDate); + } + + public double timeIntervalSinceReferenceDate () + { + return OS.objc_msgSend_fpret(this.id, OS.sel_timeIntervalSinceReferenceDate); + } + +}