Core

class UUID4

Bases: object

Represents a Universally Unique Identifier (UUID) version 4 based on a 128-bit label as specified in RFC 4122.

static from_str(value)

Creates a new [UUID4] from a string representation.

value

Gets the UUID4 value as a string.

convert_to_snake_case(input)

Convert the given string from any common case (PascalCase, camelCase, kebab-case, etc.) to lower snake_case.

Parameters:

input (str) – The input string to convert.

Return type:

str

is_within_last_24_hours(timestamp_ns)

Check whether the given UNIX nanoseconds timestamp is within the last 24 hours.

# Errors

Returns an error if the timestamp is invalid.

last_weekday_nanos(year, month, day)

Calculates the last weekday (Mon-Fri) from the given year, month, and day.

# Errors

Returns an error if the date is invalid.

mask_api_key(api_key)

Masks an API key by showing only the first and last 4 characters.

For keys 8 characters or shorter, returns asterisks only.

# Examples

``` use nautilus_core::string::secret::mask_api_key;

assert_eq!(mask_api_key(“abcdefghijklmnop”), “abcd…mnop”); assert_eq!(mask_api_key(“short”), “*”); ```

micros_to_nanos(micros)

Converts microseconds (μs) to nanoseconds (ns).

Casting f64 to u64 by truncating the fractional part is intentional for unit conversion, which may lose precision and drop negative values after clamping.

# Errors

Returns an error if micros is non-finite or cannot be represented as u64 nanoseconds.

millis_to_nanos(millis)

Converts milliseconds (ms) to nanoseconds (ns).

Casting f64 to u64 by truncating the fractional part is intentional for unit conversion, which may lose precision and drop negative values after clamping.

# Errors

Returns an error if millis is non-finite or cannot be represented as u64 nanoseconds.

nanos_to_micros(nanos)

Converts nanoseconds (ns) to microseconds (μs).

nanos_to_millis(nanos)

Converts nanoseconds (ns) to milliseconds (ms).

nanos_to_secs(nanos)

Converts nanoseconds (ns) to seconds.

Casting u64 to f64 may lose precision for large values, but is acceptable when computing fractional seconds.

secs_to_millis(secs)

Converts seconds to milliseconds (ms).

# Errors

Returns an error if secs is non-finite or cannot be represented as u64 milliseconds.

secs_to_nanos(secs)

Converts seconds to nanoseconds (ns).

# Errors

Returns an error if secs is non-finite or cannot be represented as u64 nanoseconds.

unix_nanos_to_iso8601(timestamp_ns, nanos_precision=Ellipsis)

Converts a UNIX nanoseconds timestamp to an ISO 8601 (RFC 3339) format string.

All UnixNanos values are representable by this formatter.

Datetime

dt_to_unix_nanos(value: Any) int

Return the UNIX timestamp in nanoseconds for the given datetime-like value.

is_within_last_24_hours(timestamp_ns)

Check whether the given UNIX nanoseconds timestamp is within the last 24 hours.

# Errors

Returns an error if the timestamp is invalid.

last_weekday_nanos(year, month, day)

Calculates the last weekday (Mon-Fri) from the given year, month, and day.

# Errors

Returns an error if the date is invalid.

micros_to_nanos(micros)

Converts microseconds (μs) to nanoseconds (ns).

Casting f64 to u64 by truncating the fractional part is intentional for unit conversion, which may lose precision and drop negative values after clamping.

# Errors

Returns an error if micros is non-finite or cannot be represented as u64 nanoseconds.

millis_to_nanos(millis)

Converts milliseconds (ms) to nanoseconds (ns).

Casting f64 to u64 by truncating the fractional part is intentional for unit conversion, which may lose precision and drop negative values after clamping.

# Errors

Returns an error if millis is non-finite or cannot be represented as u64 nanoseconds.

nanos_to_micros(nanos)

Converts nanoseconds (ns) to microseconds (μs).

nanos_to_millis(nanos)

Converts nanoseconds (ns) to milliseconds (ms).

nanos_to_secs(nanos)

Converts nanoseconds (ns) to seconds.

Casting u64 to f64 may lose precision for large values, but is acceptable when computing fractional seconds.

secs_to_millis(secs)

Converts seconds to milliseconds (ms).

# Errors

Returns an error if secs is non-finite or cannot be represented as u64 milliseconds.

secs_to_nanos(secs)

Converts seconds to nanoseconds (ns).

# Errors

Returns an error if secs is non-finite or cannot be represented as u64 nanoseconds.

unix_nanos_to_dt(nanos: int) Any

Return the UTC datetime for the given UNIX timestamp in nanoseconds.

unix_nanos_to_iso8601(timestamp_ns, nanos_precision=Ellipsis)

Converts a UNIX nanoseconds timestamp to an ISO 8601 (RFC 3339) format string.

All UnixNanos values are representable by this formatter.