picofuse-objc

Instance Methods | Class Methods | List of all members
NXDate Class Reference

A date and time, to the nanosecond, with the offset of a time zone. More...

#import <Foundation/Foundation.h>

Inheritance diagram for NXDate:
Inheritance graph
[legend]
Collaboration diagram for NXDate:
Collaboration graph
[legend]

Instance Methods

(id) - init
 Initializes the current date.
 
(id) - initWithSeconds:nanoseconds:
 Initializes a date from the number of seconds since 1970-01-01 in UTC.
 
(id) - initWithYear:month:day:hours:minutes:seconds:
 Initializes a date and time in UTC.
 
(id) - initWithString:format:
 Initializes a date read from a string in a format.
 
(int64_t) - seconds
 Returns the number of whole seconds since 1970-01-01 in UTC, which is negative before then.
 
(int32_t) - nanoseconds
 Returns the nanoseconds after the seconds, from zero to 999999999.
 
(int32_t) - timeZoneOffset
 Returns the offset of the time zone, in seconds east of UTC.
 
(NXDate *) - dateWithTimeZoneOffset:
 Returns the same moment in another time zone. More...
 
(NXDate *) - dateByAddingDuration:
 Returns this date with a duration added, which is earlier if it's negative. More...
 
(NXDuration) - durationSinceDate:
 Returns the time since another date, which is negative if that's later. More...
 
(NXComparisonResult) - compare:
 Compares the moments of two dates. More...
 
(BOOL) - isEqual:
 Returns YES if another object is a date at the same moment.
 
(uintptr_t) - hash
 Returns a hash of the moment, which is the same for equal dates, whatever their time zones.
 
(BOOL) - year:month:day:weekday:
 Gets the date in UTC. More...
 
(BOOL) - hours:minutes:seconds:
 Gets the time in UTC. More...
 
(BOOL) - localYear:month:day:weekday:
 Gets the date in the date's time zone. More...
 
(BOOL) - localHours:minutes:seconds:
 Gets the time in the date's time zone. More...
 
(NXString *) - stringWithFormat:
 Returns the date written in a format, or nil if the year isn't from 0 to 65535 or there isn't enough memory.
 
(NXString *) - description
 Returns the date in ISO 8601, such as "2026-09-06T11:37:05Z", or nil if the year isn't from 0 to 65535.
 
- Instance Methods inherited from NXObject
(void) - dealloc
 Frees the instance. More...
 
(NXZone *) - zone
 Returns the zone in which the instance was allocated. More...
 
(id) - retain
 Increases the retain count of the receiver. More...
 
(void) - release
 Decreases the retain count of the receiver. More...
 
(id) - autorelease
 Releases the receiver later, when the current autorelease pool of the thread is drained. More...
 
(id) - copy
 Returns a copy which can't be changed by anything else, which the caller owns and has to release. More...
 
- Instance Methods inherited from Object
(Class) - class
 Returns the class of the instance. More...
 
(Class) - superclass
 Returns the superclass of the instance. More...
 
(BOOL) - isKindOfClass:
 Returns a Boolean value that indicates whether the receiver is an instance of a given class. More...
 
(BOOL) - conformsTo:
 Checks if the receiver's class conforms to a protocol. More...
 
- Instance Methods inherited from <ObjectProtocol>
(BOOL) - respondsToSelector:
 Checks if the receiver responds to a selector. More...
 

Class Methods

(id) + date
 Returns the current date, or nil if the clock can't be read.
 
(id) + dateWithDuration:
 Returns the current date with a duration added, which is earlier if it's negative.
 
(id) + dateWithSeconds:nanoseconds:
 Returns a date from the number of seconds since 1970-01-01 in UTC. More...
 
(id) + dateWithYear:month:day:
 Returns a date at midnight in UTC, or nil if it doesn't exist. More...
 
(id) + dateWithYear:month:day:hours:minutes:seconds:
 Returns a date and time in UTC, or nil if it doesn't exist. More...
 
(id) + dateWithString:format:
 Returns a date read from a string in a format. More...
 
(id) + dateWithString:
 Returns a date read from a string in any of the formats, which are tried in turn, or nil if it isn't one.
 
(BOOL) + setCurrentDate:
 Sets the clock of the system. More...
 
- Class Methods inherited from NXObject
(id) + alloc
 Allocates a new instance in the default zone, or if there isn't one, with sys_calloc(). More...
 
(id) + allocWithZone:
 Allocates a new instance in a specific zone. More...
 
(id) + new
 Allocates and initializes a new instance, as [[cls alloc] init] does. More...
 
- Class Methods inherited from Object
(void) + initialize
 Performs one-time initialization for the class. More...
 
(Class) + class
 Returns the class object. More...
 
(Class) + superclass
 Returns the superclass of the class. More...
 
(const char *) + name
 Returns the name of the class. More...
 
(BOOL) + conformsTo:
 Checks if the class conforms to a protocol. More...
 

Additional Inherited Members

- Protected Attributes inherited from Object
Class isa
 A pointer to the object's class structure. More...
 

Detailed Description

A date and time, to the nanosecond, with the offset of a time zone.

A date is a sys_date_t of picofuse, and can't be changed once it's made. Its parts, and how it's written, are only available for the years 0 to 65535.

The time zone only changes how a date is written, and its local parts: two dates at the same moment are equal, whatever their time zones. The current date has the time zone of the system; others are in UTC unless they're given one.

On a Pico, the clock starts at 1970-01-01 when it's turned on, until it's set, and is to the millisecond.

A date can't change, so any number of threads can use it at once. See Threads and mutable objects.

Definition at line 44 of file NXDate.h.

Method Documentation

◆ compare:()

- (NXComparisonResult) compare: (NXDate *)  other

Compares the moments of two dates.

If the other is nil, it's the current date.

Returns
NXComparisonAscending if this is earlier, NXComparisonSame if they're at the same moment, or NXComparisonDescending if this is later.

◆ dateByAddingDuration:()

- (NXDate *) dateByAddingDuration: (NXDuration)  duration

Returns this date with a duration added, which is earlier if it's negative.

Returns
The date, in the same time zone, or nil if its seconds would overflow.

◆ dateWithSeconds:nanoseconds:()

+ (id) dateWithSeconds: (int64_t)  seconds
nanoseconds: (int32_t)  nanoseconds 

Returns a date from the number of seconds since 1970-01-01 in UTC.

Parameters
secondsThe seconds, which are negative before 1970.
nanosecondsThe nanoseconds after that. Any more than a second, or fewer than zero, are carried into the seconds.
Returns
The date, or nil if the seconds would overflow.

◆ dateWithString:format:()

+ (id) dateWithString: (NXString *)  string
format: (NXDateFormat)  format 

Returns a date read from a string in a format.

Parameters
stringThe whole of it is a date in the format:
  • NXDateFormatISO8601: "2026-09-06T11:37:05Z", with an optional fraction of a second, and "Z" or an offset such as "+01:00". Or just a date, "2026-09-06", which is midnight UTC.
  • NXDateFormatRFC2822: "Sun, 06 Sep 2026 11:37:05 GMT", where the weekday is optional but must be right, and the zone can be "GMT", "UTC" or an offset such as "+0100".
  • NXDateFormatLog: "2026-09-06 11:37:05", in UTC.
formatThe format.
Returns
The date, in the time zone it was written in, or nil if it isn't a date in the format or doesn't exist.

◆ dateWithTimeZoneOffset:()

- (NXDate *) dateWithTimeZoneOffset: (int32_t)  offset

Returns the same moment in another time zone.

Parameters
offsetThe offset, in seconds east of UTC. It's written in ISO 8601 to the minute.

◆ dateWithYear:month:day:()

+ (id) dateWithYear: (uint16_t)  year
month: (uint8_t)  month
day: (uint8_t)  day 

Returns a date at midnight in UTC, or nil if it doesn't exist.

Parameters
yearThe year, from 1900 to 65535.
monthThe month, from 1 to 12.
dayThe day of the month, from 1.

◆ dateWithYear:month:day:hours:minutes:seconds:()

+ (id) dateWithYear: (uint16_t)  year
month: (uint8_t)  month
day: (uint8_t)  day
hours: (uint8_t)  hours
minutes: (uint8_t)  minutes
seconds: (uint8_t)  seconds 

Returns a date and time in UTC, or nil if it doesn't exist.

Parameters
yearThe year, from 1900 to 65535.
monthThe month, from 1 to 12.
dayThe day of the month, from 1.
hoursFrom 0 to 23.
minutesFrom 0 to 59.
secondsFrom 0 to 59.

◆ durationSinceDate:()

- (NXDuration) durationSinceDate: (NXDate *)  other

Returns the time since another date, which is negative if that's later.

Parameters
otherThe other date, or nil for the current date.
Returns
The duration. Durations can be up to about 292 years, and it's the longest duration, positive or negative, if the dates are further apart.

◆ hours:minutes:seconds:()

- (BOOL) hours: (uint8_t *)  hours
minutes: (uint8_t *)  minutes
seconds: (uint8_t *)  seconds 

Gets the time in UTC.

Any of the arguments can be NULL.

Returns
YES if successful, or NO if the year isn't from 0 to 65535.

◆ localHours:minutes:seconds:()

- (BOOL) localHours: (uint8_t *)  hours
minutes: (uint8_t *)  minutes
seconds: (uint8_t *)  seconds 

Gets the time in the date's time zone.

Any of the arguments can be NULL.

Returns
YES if successful, or NO if the year isn't from 0 to 65535.

◆ localYear:month:day:weekday:()

- (BOOL) localYear: (uint16_t *)  year
month: (uint8_t *)  month
day: (uint8_t *)  day
weekday: (uint8_t *)  weekday 

Gets the date in the date's time zone.

Any of the arguments can be NULL.

Returns
YES if successful, or NO if the year isn't from 0 to 65535.

◆ setCurrentDate:()

+ (BOOL) setCurrentDate: (NXDate *)  date

Sets the clock of the system.

Returns
YES if it was set. On a Mac or Linux, that needs permission.

On a Pico, the time zone of the date becomes that of the system.

◆ year:month:day:weekday:()

- (BOOL) year: (uint16_t *)  year
month: (uint8_t *)  month
day: (uint8_t *)  day
weekday: (uint8_t *)  weekday 

Gets the date in UTC.

Any of the arguments can be NULL.

Parameters
yearThe year.
monthThe month, from 1 to 12.
dayThe day of the month, from 1.
weekdayThe day of the week, from 0 for Sunday to 6.
Returns
YES if successful, or NO if the year isn't from 0 to 65535.

The documentation for this class was generated from the following file: