view dwt/internal/cocoa/NSDate.d @ 1:8b48be5454ce

The internal cocoa classes compile now
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Tue, 19 Aug 2008 17:35:17 +0200
parents 380af2bdd8e5
children f565d3a95c0a
line wrap: on
line source

/*******************************************************************************
 * 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);
    }

}