nustack
ReferenceNu STD

datetime

Nu surface for Python's `datetime` module.

Module nustd.datetime.

Nu surface for Python's datetime module.

Mirrors datetime 1-1: the classes date / datetime / time / timedelta / timezone are Forms. datetime has no module-level functions, so there is no functions layer - just forms (the classes) and interactions (the constructor atoms; method calls use the shared nu.lang.MethodCallQuery). Import it like the stdlib:

from nustd.datetime import date, timedelta
import nustd.datetime as datetime    # datetime.date.today(), ...

ScalarQuery

NameSortCallMeaning
datescalar_querydate()datetime.date as a Form - a calendar date.
datetimescalar_querydatetime()datetime.datetime as a Form - a date and a time.
timescalar_querytime()datetime.time as a Form - a wall-clock time of day.
timedeltascalar_querytimedelta()datetime.timedelta as a Form - a span of time.
timezonescalar_querytimezone()datetime.timezone as a Form - a fixed offset from UTC.

date

datetime.date as a Form - a calendar date.

date()

Path nustd.datetime.date. Kind ScalarQuery, sort scalar_query, cardinality scalar.

Methods

date.of(year, month, day)

Build a date: date(year, month, day).

Builds date.

Arguments

NameTypeDefaultMeaning
yearIntArg
monthIntArg
dayIntArg

Undocumented: example.

date.today()

Today's date: date.today().

Builds date.

Undocumented: example.

date.from_iso(value)

Parse an ISO date string: date.fromisoformat(s).

Builds date.

Arguments

NameTypeDefaultMeaning
valueStrArg

Undocumented: example.

date.from_ordinal(value)

From a proleptic Gregorian ordinal: date.fromordinal(n).

Builds date.

Arguments

NameTypeDefaultMeaning
valueIntArg

Undocumented: example.

date.from_timestamp(value)

From a POSIX timestamp: date.fromtimestamp(t).

Builds date.

Arguments

NameTypeDefaultMeaning
valueFloatArg

Undocumented: example.

.year()

The year.

Builds Int.

Undocumented: example.

.month()

The month (1..12).

Builds Int.

Undocumented: example.

.day()

The day of the month (1..31).

Builds Int.

Undocumented: example.

.weekday()

The day of week, Monday=0.

Builds Int.

Undocumented: example.

.isoweekday()

The day of week, Monday=1.

Builds Int.

Undocumented: example.

.toordinal()

The proleptic Gregorian ordinal.

Builds Int.

Undocumented: example.

.isoformat()

The date as an ISO string (YYYY-MM-DD).

Builds Str.

Undocumented: example.

.ctime()

The date as a C-style string.

Builds Str.

Undocumented: example.

.strftime(fmt)

Format the date with a strftime pattern.

Builds Str.

Arguments

NameTypeDefaultMeaning
fmtStrArg

Undocumented: example.

.replace(year=None, month=None, day=None)

A copy with the given components replaced.

Builds date.

Arguments

NameTypeDefaultMeaning
yearIntArg | NoneNone
monthIntArg | NoneNone
dayIntArg | NoneNone

Undocumented: example.

a + b

Builds date.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg

Undocumented: summary, example.

a - b

Builds date | timedelta.

Arguments

NameTypeDefaultMeaning
otherDateArg | TimedeltaArg

Undocumented: summary, example.

a > b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDateArg

Undocumented: summary, example.

a < b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDateArg

Undocumented: summary, example.

a >= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDateArg

Undocumented: summary, example.

a <= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDateArg

Undocumented: summary, example.

.eq(other)

Whether two dates are equal.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDateArg

Undocumented: example.

.ne(other)

Whether two dates differ.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDateArg

Undocumented: example.

Inherited methods

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

Undocumented: example.

datetime

datetime.datetime as a Form - a date and a time.

datetime()

Path nustd.datetime.datetime. Kind ScalarQuery, sort scalar_query, cardinality scalar.

Methods

datetime.of(year, month, day, hour=0, minute=0, second=0, microsecond=0)

Build a datetime: datetime(year, month, day, hour, ...).

Builds datetime.

Arguments

NameTypeDefaultMeaning
yearIntArg
monthIntArg
dayIntArg
hourIntArg0
minuteIntArg0
secondIntArg0
microsecondIntArg0

Undocumented: example.

datetime.now(tz=None)

The current local (or tz) datetime: datetime.now(tz).

Builds datetime.

Arguments

NameTypeDefaultMeaning
tzTimezoneArg | NoneNone

Undocumented: example.

datetime.from_iso(value)

Parse an ISO datetime string: datetime.fromisoformat(s).

Builds datetime.

Arguments

NameTypeDefaultMeaning
valueStrArg

Undocumented: example.

datetime.from_timestamp(value, tz=None)

From a POSIX timestamp: datetime.fromtimestamp(ts, tz).

Builds datetime.

Arguments

NameTypeDefaultMeaning
valueFloatArg
tzTimezoneArg | NoneNone

Undocumented: example.

datetime.combine(date_value, time_value)

Combine a date and a time: datetime.combine(date, time).

Builds datetime.

Arguments

NameTypeDefaultMeaning
date_valueDateArg
time_valueTimeArg

Undocumented: example.

.year()

The year.

Builds Int.

Undocumented: example.

.month()

The month (1..12).

Builds Int.

Undocumented: example.

.day()

The day of the month (1..31).

Builds Int.

Undocumented: example.

.hour()

The hour (0..23).

Builds Int.

Undocumented: example.

.minute()

The minute (0..59).

Builds Int.

Undocumented: example.

.second()

The second (0..59).

Builds Int.

Undocumented: example.

.microsecond()

The microsecond (0..999999).

Builds Int.

Undocumented: example.

.weekday()

The day of week, Monday=0.

Builds Int.

Undocumented: example.

.isoweekday()

The day of week, Monday=1.

Builds Int.

Undocumented: example.

.timestamp()

The POSIX timestamp.

Builds Float.

Undocumented: example.

.isoformat()

The datetime as an ISO string.

Builds Str.

Undocumented: example.

.strftime(fmt)

Format the datetime with a strftime pattern.

Builds Str.

Arguments

NameTypeDefaultMeaning
fmtStrArg

Undocumented: example.

.date()

The date part.

Builds date.

Undocumented: example.

.time()

The time part.

Builds time.

Undocumented: example.

.replace(year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None)

A copy with the given components replaced.

Builds datetime.

Arguments

NameTypeDefaultMeaning
yearIntArg | NoneNone
monthIntArg | NoneNone
dayIntArg | NoneNone
hourIntArg | NoneNone
minuteIntArg | NoneNone
secondIntArg | NoneNone
microsecondIntArg | NoneNone

Undocumented: example.

a + b

Builds datetime.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg

Undocumented: summary, example.

a - b

Builds datetime | timedelta.

Arguments

NameTypeDefaultMeaning
otherDatetimeArg | TimedeltaArg

Undocumented: summary, example.

a > b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDatetimeArg

Undocumented: summary, example.

a < b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDatetimeArg

Undocumented: summary, example.

a >= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDatetimeArg

Undocumented: summary, example.

a <= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDatetimeArg

Undocumented: summary, example.

.eq(other)

Whether two datetimes are equal.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDatetimeArg

Undocumented: example.

.ne(other)

Whether two datetimes differ.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherDatetimeArg

Undocumented: example.

Inherited methods

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

Undocumented: example.

time

datetime.time as a Form - a wall-clock time of day.

time()

Path nustd.datetime.time. Kind ScalarQuery, sort scalar_query, cardinality scalar.

Methods

time.of(hour=0, minute=0, second=0, microsecond=0)

Build a time: time(hour, minute, second, microsecond).

Builds time.

Arguments

NameTypeDefaultMeaning
hourIntArg0
minuteIntArg0
secondIntArg0
microsecondIntArg0

Undocumented: example.

time.from_iso(value)

Parse an ISO time string: time.fromisoformat(s).

Builds time.

Arguments

NameTypeDefaultMeaning
valueStrArg

Undocumented: example.

.hour()

The hour (0..23).

Builds Int.

Undocumented: example.

.minute()

The minute (0..59).

Builds Int.

Undocumented: example.

.second()

The second (0..59).

Builds Int.

Undocumented: example.

.microsecond()

The microsecond (0..999999).

Builds Int.

Undocumented: example.

.isoformat()

The time as an ISO string.

Builds Str.

Undocumented: example.

.strftime(fmt)

Format the time with a strftime pattern.

Builds Str.

Arguments

NameTypeDefaultMeaning
fmtStrArg

Undocumented: example.

.replace(hour=None, minute=None, second=None, microsecond=None)

A copy with the given components replaced.

Builds time.

Arguments

NameTypeDefaultMeaning
hourIntArg | NoneNone
minuteIntArg | NoneNone
secondIntArg | NoneNone
microsecondIntArg | NoneNone

Undocumented: example.

a > b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimeArg

Undocumented: summary, example.

a < b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimeArg

Undocumented: summary, example.

a >= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimeArg

Undocumented: summary, example.

a <= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimeArg

Undocumented: summary, example.

.eq(other)

Whether two times are equal.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimeArg

Undocumented: example.

.ne(other)

Whether two times differ.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimeArg

Undocumented: example.

Inherited methods

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

Undocumented: example.

timedelta

datetime.timedelta as a Form - a span of time.

timedelta()

Path nustd.datetime.timedelta. Kind ScalarQuery, sort scalar_query, cardinality scalar.

Methods

timedelta.of(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)

Build a timedelta from its components: timedelta(...).

Builds timedelta.

Arguments

NameTypeDefaultMeaning
daysIntArg | FloatArg0
secondsIntArg | FloatArg0
microsecondsIntArg | FloatArg0
millisecondsIntArg | FloatArg0
minutesIntArg | FloatArg0
hoursIntArg | FloatArg0
weeksIntArg | FloatArg0

Undocumented: example.

.days()

The whole-days component.

Builds Int.

Undocumented: example.

.seconds()

The seconds component (0..86399).

Builds Int.

Undocumented: example.

.microseconds()

The microseconds component (0..999999).

Builds Int.

Undocumented: example.

.total_seconds()

The total duration in seconds.

Builds Float.

Undocumented: example.

a + b

Builds timedelta.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg

Undocumented: summary, example.

a - b

Builds timedelta.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg

Undocumented: summary, example.

a * b

Builds timedelta.

Arguments

NameTypeDefaultMeaning
factorIntArg | FloatArg

Undocumented: summary, example.

a / b

Builds timedelta | Float.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg | IntArg | FloatArg

Undocumented: summary, example.

a // b

Builds timedelta.

Arguments

NameTypeDefaultMeaning
otherIntArg

Undocumented: summary, example.

a % b

Builds timedelta.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg

Undocumented: summary, example.

-a

Builds timedelta.

Undocumented: summary, example.

abs(a)

Builds timedelta.

Undocumented: summary, example.

+a

Builds timedelta.

Undocumented: summary, example.

a > b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg

Undocumented: summary, example.

a < b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg

Undocumented: summary, example.

a >= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg

Undocumented: summary, example.

a <= b

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg

Undocumented: summary, example.

.eq(other)

Whether two spans are equal.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg

Undocumented: example.

.ne(other)

Whether two spans differ.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimedeltaArg

Undocumented: example.

Inherited methods

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

Undocumented: example.

timezone

datetime.timezone as a Form - a fixed offset from UTC.

timezone()

Path nustd.datetime.timezone. Kind ScalarQuery, sort scalar_query, cardinality scalar.

Methods

timezone.of(offset, name=None)

Build a fixed-offset zone: timezone(offset, name).

Builds timezone.

Arguments

NameTypeDefaultMeaning
offsetTimedeltaArg
nameStrArg | NoneNone

Undocumented: example.

timezone.utc()

The UTC zone: timezone.utc.

Builds timezone.

Undocumented: example.

.utcoffset(dt=None)

The offset from UTC as a timedelta.

Builds timedelta.

Arguments

NameTypeDefaultMeaning
dtDatetimeArg | NoneNone

Undocumented: example.

.tzname(dt=None)

The zone's name.

Builds Str.

Arguments

NameTypeDefaultMeaning
dtDatetimeArg | NoneNone

Undocumented: example.

.dst(dt=None)

Daylight-saving adjustment (always None for a fixed offset).

Builds None_.

Arguments

NameTypeDefaultMeaning
dtDatetimeArg | NoneNone

Undocumented: example.

.eq(other)

Whether two zones are equal.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimezoneArg

Undocumented: example.

.ne(other)

Whether two zones differ.

Builds Bool.

Arguments

NameTypeDefaultMeaning
otherTimezoneArg

Undocumented: example.

Inherited methods

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

Undocumented: example.

On this page