nk 1.0.0
C++ Numerical Computing Runtime
Loading...
Searching...
No Matches
Time and Dates (timefun)

System clock, benchmarking timers (tic/toc), date calculations, and execution pauses. More...

Files

file  timefun.hpp
 Date, time, high-resolution profiling timers, and calendar utilities.

Functions

double nk::builtin::cputime ()
 Total CPU time consumed by the current process in seconds (cputime).
void nk::builtin::pause (double seconds)
 Halts execution for specified number of seconds (pause(n)).
double nk::builtin::now ()
 Current date and time as a serial date number (now).
std::string nk::builtin::date ()
 Current date as formatted text 'dd-mmm-yyyy' (date).
Value nk::builtin::clock (std::pmr::memory_resource *mr=nullptr)
 Current date and time as a 6-element vector [Y, M, D, H, MI, S] (clock).
Value nk::builtin::etime (const Value &t2, const Value &t1, std::pmr::memory_resource *mr=nullptr)
 Elapsed time in seconds between two date vectors (etime(t2, t1)).
Value nk::builtin::datenum (Span< const Value > args, std::pmr::memory_resource *mr=nullptr)
 Converts date components or string to serial date number (datenum(...)).
Value nk::builtin::datestr (Span< const Value > args, std::pmr::memory_resource *mr=nullptr)
 Formats serial date number or date vector into text string (datestr(...)).
Value nk::builtin::datevec (Span< const Value > args, std::pmr::memory_resource *mr=nullptr)
 Converts serial date number or text into date vector matrix [Y, M, D, H, MI, S] (datevec(...)).
Value nk::builtin::weekday (const Value &d, std::pmr::memory_resource *mr=nullptr)
 Day of week for date number or text (weekday(d)).
Value nk::builtin::eomday (const Value &y, const Value &m, std::pmr::memory_resource *mr=nullptr)
 End of month day for year and month (eomday(y, m)).
Value nk::builtin::calendar (Span< const Value > args, std::pmr::memory_resource *mr=nullptr)
 Generates 6x7 calendar matrix for year and month (calendar(...)).
Value nk::builtin::juliandate (Span< const Value > args, std::pmr::memory_resource *mr=nullptr)
 Julian date number from serial date or date components (juliandate(...)).
Value nk::builtin::mjuliandate (Span< const Value > args, std::pmr::memory_resource *mr=nullptr)
 Modified Julian date number (mjuliandate(...)).
Value nk::builtin::weeknum (Span< const Value > args, std::pmr::memory_resource *mr=nullptr)
 Week number of the year for a given date (weeknum(...)).
Value nk::builtin::addtodate (const Value &d, double quantity, const std::string &unit, std::pmr::memory_resource *mr=nullptr)
 Shifts date by quantity in specified time units (addtodate(d, q, unit)).
Value nk::builtin::yyyymmdd (Span< const Value > args, std::pmr::memory_resource *mr=nullptr)
 Formats date number as ISO integer YYYYMMDD (yyyymmdd(...)).

Detailed Description

System clock, benchmarking timers (tic/toc), date calculations, and execution pauses.

Function Documentation

◆ addtodate()

Value nk::builtin::addtodate ( const Value & d,
double quantity,
const std::string & unit,
std::pmr::memory_resource * mr = nullptr )

Shifts date by quantity in specified time units (addtodate(d, q, unit)).

Parameters
dSerial date number.
quantityAmount to add.
unitTime unit string ('day', 'month', 'year', 'hour', 'minute', 'second', 'millisecond').
mrMemory resource.
Returns
Shifted serial date number.

◆ calendar()

Value nk::builtin::calendar ( Span< const Value > args,
std::pmr::memory_resource * mr = nullptr )

Generates 6x7 calendar matrix for year and month (calendar(...)).

Parameters
argsSpan containing () for current month, (d) for date, or (y, m).
mrMemory resource.
Returns
6 x 7 calendar matrix.
See also
weekday, eomday

◆ clock()

Value nk::builtin::clock ( std::pmr::memory_resource * mr = nullptr)

Current date and time as a 6-element vector [Y, M, D, H, MI, S] (clock).

Parameters
mrMemory resource for allocations (nullptr for default).
Returns
1 x 6 matrix of current date and time components.
See also
datevec, now, date

◆ cputime()

double nk::builtin::cputime ( )

Total CPU time consumed by the current process in seconds (cputime).

Measures CPU execution time across all threads. Useful for profiling algorithm efficiency.

Returns
Total elapsed CPU seconds since process start as a double.
See also
tic, toc, pause, clock

◆ date()

std::string nk::builtin::date ( )

Current date as formatted text 'dd-mmm-yyyy' (date).

Returns
Date string.
See also
now, clock, datestr

◆ datenum()

Value nk::builtin::datenum ( Span< const Value > args,
std::pmr::memory_resource * mr = nullptr )

Converts date components or string to serial date number (datenum(...)).

Parameters
argsSpan of arguments (e.g. (str [, fmt]) or (Y, M, D [, H, MI, S])).
mrMemory resource.
Returns
Serial date number array or scalar.
See also
datestr, datevec, now

◆ datestr()

Value nk::builtin::datestr ( Span< const Value > args,
std::pmr::memory_resource * mr = nullptr )

Formats serial date number or date vector into text string (datestr(...)).

Parameters
argsSpan of arguments (e.g. (D [, fmt]) or (D, fmt, P)).
mrMemory resource.
Returns
Character array or string representation.
See also
datenum, datevec

◆ datevec()

Value nk::builtin::datevec ( Span< const Value > args,
std::pmr::memory_resource * mr = nullptr )

Converts serial date number or text into date vector matrix [Y, M, D, H, MI, S] (datevec(...)).

Parameters
argsSpan of arguments (e.g. (D) or (str [, fmt])).
mrMemory resource.
Returns
N x 6 matrix of date components.
See also
datenum, datestr, clock

◆ eomday()

Value nk::builtin::eomday ( const Value & y,
const Value & m,
std::pmr::memory_resource * mr = nullptr )

End of month day for year and month (eomday(y, m)).

Parameters
yYear.
mMonth (1 to 12).
mrMemory resource.
Returns
Number of days in the month (28, 29, 30, or 31).
See also
weekday, calendar

◆ etime()

Value nk::builtin::etime ( const Value & t2,
const Value & t1,
std::pmr::memory_resource * mr = nullptr )

Elapsed time in seconds between two date vectors (etime(t2, t1)).

Parameters
t2Ending date vector(s) (N x 6 or 1 x 6).
t1Starting date vector(s) (N x 6 or 1 x 6).
mrMemory resource.
Returns
Column vector of elapsed seconds.
See also
clock, datevec

◆ juliandate()

Value nk::builtin::juliandate ( Span< const Value > args,
std::pmr::memory_resource * mr = nullptr )

Julian date number from serial date or date components (juliandate(...)).

Parameters
argsSpan of arguments (D) or (Y, M, D [, H, MI, S]).
mrMemory resource.
Returns
Julian date number.
See also
mjuliandate, datenum

◆ mjuliandate()

Value nk::builtin::mjuliandate ( Span< const Value > args,
std::pmr::memory_resource * mr = nullptr )

Modified Julian date number (mjuliandate(...)).

Parameters
argsSpan of arguments (D) or (Y, M, D [, H, MI, S]).
mrMemory resource.
Returns
Modified Julian date (JD - 2400000.5).
See also
juliandate, datenum

◆ now()

double nk::builtin::now ( )

Current date and time as a serial date number (now).

Returns
Serial date number (days since 0000-01-00).
See also
clock, date, datenum

◆ pause()

void nk::builtin::pause ( double seconds)

Halts execution for specified number of seconds (pause(n)).

Suspends current thread execution for the specified duration.

Parameters
secondsDuration to pause in seconds (supports fractional seconds).
See also
cputime, tic, toc

◆ weekday()

Value nk::builtin::weekday ( const Value & d,
std::pmr::memory_resource * mr = nullptr )

Day of week for date number or text (weekday(d)).

Parameters
dSerial date number or text representation.
mrMemory resource.
Returns
Day of week integer (1=Sunday, 2=Monday, ..., 7=Saturday).
See also
eomday, calendar

◆ weeknum()

Value nk::builtin::weeknum ( Span< const Value > args,
std::pmr::memory_resource * mr = nullptr )

Week number of the year for a given date (weeknum(...)).

Parameters
argsSpan of arguments (D [, weekStart [, european]]).
mrMemory resource.
Returns
Week of year number.

◆ yyyymmdd()

Value nk::builtin::yyyymmdd ( Span< const Value > args,
std::pmr::memory_resource * mr = nullptr )

Formats date number as ISO integer YYYYMMDD (yyyymmdd(...)).

Parameters
argsSpan of arguments.
mrMemory resource.
Returns
Array of packed YYYYMMDD integer values.