1995-03-31 15:39:12 +00:00
|
|
|
/* Interface for NSDate for GNUStep
|
1999-09-16 07:21:34 +00:00
|
|
|
Copyright (C) 1994, 1996, 1999 Free Software Foundation, Inc.
|
1995-03-31 15:39:12 +00:00
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1995-03-31 15:39:12 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-09-14 11:36:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1995-03-31 15:39:12 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-08 10:38:33 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
1995-03-31 15:39:12 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
2007-09-14 11:36:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1995-03-31 15:39:12 +00:00
|
|
|
License along with this library; if not, write to the Free
|
2006-10-31 07:05:46 +00:00
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02111 USA.
|
1999-09-16 07:21:34 +00:00
|
|
|
*/
|
1995-03-31 15:39:12 +00:00
|
|
|
|
1996-04-17 19:36:35 +00:00
|
|
|
#ifndef __NSDate_h_GNUSTEP_BASE_INCLUDE
|
|
|
|
#define __NSDate_h_GNUSTEP_BASE_INCLUDE
|
2006-10-31 07:05:46 +00:00
|
|
|
#import <GNUstepBase/GSVersionMacros.h>
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
#import <Foundation/NSObjCRuntime.h>
|
2002-11-01 08:11:46 +00:00
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-06-20 23:34:46 +00:00
|
|
|
GS_EXPORT NSString * const NSSystemClockDidChangeNotification;
|
|
|
|
|
2002-11-01 08:11:46 +00:00
|
|
|
/**
|
|
|
|
* Time interval difference between two dates, in seconds.
|
|
|
|
*/
|
1996-03-12 14:43:55 +00:00
|
|
|
typedef double NSTimeInterval;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2002-11-01 08:11:46 +00:00
|
|
|
/**
|
|
|
|
* Time interval between the unix standard reference date of 1 January 1970
|
|
|
|
* and the OpenStep reference date of 1 January 2001<br />
|
|
|
|
* This number comes from:<br />
|
|
|
|
* (((31 years * 365 days) + 8 days for leap years) = total number of days<br />
|
|
|
|
* 24 hours * 60 minutes * 60 seconds)<br />
|
|
|
|
* This ignores leap-seconds.
|
|
|
|
*/
|
|
|
|
GS_EXPORT const NSTimeInterval NSTimeIntervalSince1970;
|
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
#import <Foundation/NSObject.h>
|
1998-04-02 14:27:40 +00:00
|
|
|
|
1995-08-23 15:19:46 +00:00
|
|
|
@class NSArray;
|
1995-03-31 15:39:12 +00:00
|
|
|
@class NSCalendarDate;
|
2001-01-30 20:47:05 +00:00
|
|
|
@class NSData;
|
1995-08-23 15:19:46 +00:00
|
|
|
@class NSDictionary;
|
1995-03-31 15:39:12 +00:00
|
|
|
@class NSString;
|
|
|
|
@class NSTimeZone;
|
1995-08-23 15:19:46 +00:00
|
|
|
@class NSTimeZoneDetail;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
1997-09-01 21:59:51 +00:00
|
|
|
@interface NSDate : NSObject <NSCoding,NSCopying>
|
1996-10-31 17:14:00 +00:00
|
|
|
{
|
|
|
|
}
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns an autoreleased instance with the current date/time.
|
|
|
|
*/
|
|
|
|
+ (id) date;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
|
|
|
/** Returns an autoreleased instance representing the date and time given
|
|
|
|
* by string. The value of string may be a 'natural' specification as
|
|
|
|
* specified by the preferences in the user defaults database, allowing
|
|
|
|
* phrases like 'last tuesday'
|
|
|
|
*/
|
|
|
|
+ (id) dateWithNaturalLanguageString: (NSString*)string;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/**
|
|
|
|
* <p>Returns an autoreleased instance representing the date and time given
|
|
|
|
* by string. The value of string may be a 'natural' specification as
|
|
|
|
* specified by the preferences in the user defaults database, allowing
|
|
|
|
* phrases like 'last tuesday'
|
|
|
|
* </p>
|
|
|
|
* The locale contains keys such as -
|
|
|
|
* <deflist>
|
|
|
|
* <term>NSDateTimeOrdering</term>
|
|
|
|
* <desc>Controls the use of ambiguous numbers. This is done as a
|
|
|
|
* sequence of the letters D(ay), M(onth), Y(ear), and H(our).
|
|
|
|
* YMDH means that the first number encountered is assumed to be a
|
|
|
|
* year, the second a month, the third a day, and the last an hour.
|
|
|
|
* </desc>
|
|
|
|
* <term>NSEarlierTimeDesignations</term>
|
|
|
|
* <desc>An array of strings for times in the past.<br />
|
|
|
|
* Defaults are <em>ago</em>, <em>last</em>, <em>past</em>, <em>prior</em>
|
|
|
|
* </desc>
|
|
|
|
* <term>NSHourNameDesignations</term>
|
|
|
|
* <desc>An array of arrays of strings identifying the time of day.
|
|
|
|
* Each array has an hour as its first value, and one or more words
|
|
|
|
* as subsequent values.<br />
|
|
|
|
* Defaults are: (0, midnight), (10, morning), (12, noon, lunch),
|
|
|
|
* (14, afternoon), (19, dinner).
|
|
|
|
* </desc>
|
|
|
|
* <term>NSLaterTimeDesignations</term>
|
|
|
|
* <desc>An array of strings for times in the future.<br />
|
|
|
|
* Default is <em>next</em>
|
|
|
|
* </desc>
|
|
|
|
* <term>NSNextDayDesignations</term>
|
|
|
|
* <desc>The day after today. Default is <em>tomorrow.</em>
|
|
|
|
* </desc>
|
|
|
|
* <term>NSNextNextDayDesignations</term>
|
|
|
|
* <desc>The day after tomorrow. Default is <em>nextday.</em>
|
|
|
|
* </desc>
|
|
|
|
* <term>NSPriorDayDesignations</term>
|
|
|
|
* <desc>The day before today. Default is <em>yesterday.</em>
|
|
|
|
* </desc>
|
|
|
|
* <term>NSThisDayDesignations</term>
|
|
|
|
* <desc>Identifies the current day. Default is <em>today.</em>
|
|
|
|
* </desc>
|
|
|
|
* <term>NSYearMonthWeekDesignations</term>
|
|
|
|
* <desc>An array giving the word for year, month, and week.<br />
|
|
|
|
* Defaults are <em>year</em>, <em>month</em> and <em>week</em>.
|
|
|
|
* </desc>
|
|
|
|
* </deflist>
|
|
|
|
*/
|
|
|
|
+ (id) dateWithNaturalLanguageString: (NSString*)string
|
|
|
|
locale: (NSDictionary*)locale;
|
|
|
|
#endif
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns an autoreleased instance with the date and time value given
|
|
|
|
* by the string using the ISO standard format YYYY-MM-DD HH:MM:SS +/-HHHMM
|
|
|
|
* (all the fields of which must be present).
|
|
|
|
*/
|
1998-01-21 14:56:24 +00:00
|
|
|
+ (id) dateWithString: (NSString*)description;
|
2016-10-21 15:32:31 +00:00
|
|
|
|
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
|
|
|
/** Returns an autoreleased NSDate instance whose value is offset from
|
|
|
|
* that of the given date by the specified interval in seconds.
|
|
|
|
*/
|
|
|
|
+ (id) dateWithTimeInterval: (NSTimeInterval)seconds sinceDate: (NSDate*)date;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Returns an autoreleased instance with the offset from the unix system
|
|
|
|
* reference date of 1 January 1970, GMT.
|
|
|
|
*/
|
1998-01-21 14:56:24 +00:00
|
|
|
+ (id) dateWithTimeIntervalSince1970: (NSTimeInterval)seconds;
|
2016-10-21 15:32:31 +00:00
|
|
|
|
|
|
|
/** Returns an autoreleased instance with the offset from the current
|
|
|
|
* date/time given by seconds (which may be fractional).
|
|
|
|
*/
|
|
|
|
+ (id) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds;
|
|
|
|
|
|
|
|
/** Returns an autoreleased instance with the offset from the OpenStep
|
|
|
|
* reference date of 1 January 2001, GMT.
|
|
|
|
*/
|
1998-01-21 14:56:24 +00:00
|
|
|
+ (id) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds;
|
2016-10-21 15:32:31 +00:00
|
|
|
|
|
|
|
/** Returns an autoreleased instance with the date/time set in the far
|
|
|
|
* past.
|
|
|
|
*/
|
1998-01-21 14:56:24 +00:00
|
|
|
+ (id) distantPast;
|
1996-10-31 17:14:00 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns an autoreleased instance with the date/time set in the far
|
|
|
|
* future.
|
|
|
|
*/
|
|
|
|
+ (id) distantFuture;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns the time interval between the reference date and the current
|
|
|
|
* time.
|
|
|
|
*/
|
|
|
|
+ (NSTimeInterval) timeIntervalSinceReferenceDate;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns an autorelease date instance formed by adding the specified
|
|
|
|
* time interval in seconds to the receiver's time interval.
|
|
|
|
*/
|
|
|
|
- (id) addTimeInterval: (NSTimeInterval)seconds;
|
|
|
|
|
|
|
|
/** Returns the time interval between the receivers value and the
|
|
|
|
* OpenStep reference date of 1 Jan 2001 GMT.
|
|
|
|
*/
|
|
|
|
- (NSComparisonResult) compare: (NSDate*)otherDate;
|
|
|
|
|
|
|
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
|
|
|
|
/** Returns an autoreleased NSDate instance whose value is offset from
|
|
|
|
* that of the receiver by the specified interval.
|
|
|
|
*/
|
|
|
|
- (id) dateByAddingTimeInterval: (NSTimeInterval)ti;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Returns an autoreleased instance of the [NSCalendarDate] class whose
|
|
|
|
* date/time value is the same as that of the receiver, and which uses
|
|
|
|
* the formatString and timeZone specified.
|
|
|
|
*/
|
1999-09-16 07:21:34 +00:00
|
|
|
- (NSCalendarDate*) dateWithCalendarFormat: (NSString*)formatString
|
|
|
|
timeZone: (NSTimeZone*)timeZone;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns a string representation of the receiver formatted according
|
|
|
|
* to the default format string, time zone, and locale.
|
|
|
|
*/
|
1995-03-31 15:39:12 +00:00
|
|
|
- (NSString*) description;
|
2016-10-21 15:32:31 +00:00
|
|
|
|
|
|
|
/** Returns a string representation of the receiver formatted according
|
|
|
|
* to the specified format string, time zone, and locale.
|
|
|
|
*/
|
1995-04-13 22:13:59 +00:00
|
|
|
- (NSString*) descriptionWithCalendarFormat: (NSString*)format
|
1998-11-30 10:04:24 +00:00
|
|
|
timeZone: (NSTimeZone*)aTimeZone
|
2001-12-17 14:31:42 +00:00
|
|
|
locale: (NSDictionary*)l;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns a string representation of the receiver formatted according
|
|
|
|
* to the default format string and time zone, but using the given locale.
|
|
|
|
*/
|
|
|
|
- (NSString*) descriptionWithLocale: (id)locale;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns the earlier of the receiver and otherDate.<br />
|
|
|
|
* If the two represent identical date/time values, returns the receiver.
|
|
|
|
*/
|
|
|
|
- (NSDate*) earlierDate: (NSDate*)otherDate;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns an instance initialised with the current date/time.
|
|
|
|
*/
|
|
|
|
- (id) init;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns an instance with the date and time value given
|
|
|
|
* by the string using the ISO standard format YYYY-MM-DD HH:MM:SS +/-HHHMM
|
|
|
|
* (all the fields of which must be present).
|
|
|
|
*/
|
|
|
|
- (id) initWithString: (NSString*)description;
|
1995-03-31 15:39:12 +00:00
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns an instance with the given offset from anotherDate.
|
2012-09-10 05:18:09 +00:00
|
|
|
*/
|
2016-10-21 15:32:31 +00:00
|
|
|
- (id) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
|
|
|
|
sinceDate: (NSDate*)anotherDate;
|
2012-09-10 05:18:09 +00:00
|
|
|
|
2006-10-31 07:05:46 +00:00
|
|
|
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns an instance with the offset from the unix system
|
|
|
|
* reference date of 1 January 1970, GMT.
|
|
|
|
*/
|
1998-12-18 17:05:44 +00:00
|
|
|
- (id) initWithTimeIntervalSince1970: (NSTimeInterval)seconds;
|
|
|
|
#endif
|
|
|
|
|
2016-10-21 15:32:31 +00:00
|
|
|
/** Returns an instance with the offset from the current date/time.
|
|
|
|
*/
|
|
|
|
- (id) initWithTimeIntervalSinceNow: (NSTimeInterval)secsToBeAdded;
|
|
|
|
|
|
|
|
/** <init />
|
|
|
|
* Returns an instance with the given offset from the OpenStep
|
|
|
|
* reference date of 1 January 2001, GMT.
|
|
|
|
*/
|
|
|
|
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs;
|
|
|
|
|
|
|
|
/** Returns NO if other is not a date, otherwise returns the result of
|
|
|
|
* calling the -isEqualtoDate: method.
|
|
|
|
*/
|
|
|
|
- (BOOL) isEqual: (id)other;
|
|
|
|
|
|
|
|
/** Returns whether the receiver is exactly equal to other, to the limit
|
|
|
|
* of the NSTimeInterval precision.<br />
|
|
|
|
* This is the behavior of the current MacOS-X system, not that of the
|
|
|
|
* OpenStep specification (which counted two dates within a second of
|
|
|
|
* each other as being equal).<br />
|
|
|
|
* The old behavior meant that two dates equal to a third date were not
|
|
|
|
* necessarily equal to each other (confusing), and meant that there was
|
|
|
|
* no reasonable way to use a date as a dictionary key or store dates
|
|
|
|
* in a set.
|
|
|
|
*/
|
|
|
|
- (BOOL) isEqualToDate: (NSDate*)other;
|
|
|
|
|
|
|
|
/** Returns the earlier of the receiver and otherDate.<br />
|
|
|
|
* If the two represent identical date/time values, returns the receiver.
|
|
|
|
*/
|
|
|
|
- (NSDate*) laterDate: (NSDate*)otherDate;
|
|
|
|
|
|
|
|
/** Returns the time interval between the receivers value and the
|
|
|
|
* unix system reference date of 1 January 1970, GMT.
|
|
|
|
*/
|
|
|
|
- (NSTimeInterval) timeIntervalSince1970;
|
|
|
|
|
|
|
|
/** Returns the time interval between the receivers value and that of the
|
|
|
|
* otherDate argument. If otherDate is earlier than the receiver, the
|
|
|
|
* returned value will be positive, if it is later it will be negative.<br />
|
|
|
|
* For current (2011) OSX compatibility, this method returns NaN if otherDate
|
|
|
|
* is nil ... do not write code depending on that behavior.
|
|
|
|
*/
|
|
|
|
- (NSTimeInterval) timeIntervalSinceDate: (NSDate*)otherDate;
|
|
|
|
|
|
|
|
/** Returns the time interval between the receivers value and the
|
|
|
|
* current date/time. If the receiver represents a date/time in
|
|
|
|
* the past this will be negative, if it is in the future the
|
|
|
|
* returned value will be positive.
|
|
|
|
*/
|
|
|
|
- (NSTimeInterval) timeIntervalSinceNow;
|
|
|
|
|
|
|
|
/** Returns the time interval between the receivers value and the
|
|
|
|
* OpenStep reference date of 1 Jan 2001 GMT.
|
|
|
|
*/
|
|
|
|
- (NSTimeInterval) timeIntervalSinceReferenceDate;
|
|
|
|
|
1995-03-31 15:39:12 +00:00
|
|
|
@end
|
|
|
|
|
2006-09-13 10:20:49 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-09-16 07:21:34 +00:00
|
|
|
#endif /* __NSDate_h_GNUSTEP_BASE_INCLUDE*/
|