Expand description
Time utilities for CCXT
This module provides comprehensive time-related utility functions for timestamp conversion,
date parsing, formatting, and validation. All timestamps are standardized to use i64 type
representing milliseconds since Unix epoch unless otherwise specified.
§Key Features
- Standardized i64 timestamps: All timestamps use
i64for consistency - Comprehensive validation: Range checking and overflow protection
- Migration support: Conversion utilities for u64 to i64 migration
- Multiple format support: ISO 8601, space-separated, and custom formats
- UTC timezone handling: All operations in UTC for consistency
- Error handling: Proper error types for all failure modes
§Timestamp Format Standard
- Type:
i64 - Unit: Milliseconds since Unix Epoch (January 1, 1970, 00:00:00 UTC)
- Range: 0 to ~292,277,026,596 (year ~294,276)
- Validation: Must be >= 0 for valid Unix timestamps
§Example
use ccxt_core::time::{TimestampUtils, milliseconds, iso8601, parse_date};
// Get current timestamp in milliseconds
let now = milliseconds();
// Validate timestamp
let validated = TimestampUtils::validate_timestamp(now).unwrap();
// Convert timestamp to ISO 8601 string
let iso_str = iso8601(validated).unwrap();
// Parse ISO 8601 string back to timestamp
let parsed = parse_date(&iso_str).unwrap();
assert_eq!(validated, parsed);
// Migration support: convert u64 to i64
let old_timestamp: u64 = 1704110400000;
let new_timestamp = TimestampUtils::u64_to_i64(old_timestamp).unwrap();Structs§
- Timestamp
Utils - Comprehensive timestamp utilities for consistent i64 handling
Traits§
- Timestamp
Conversion - Extension trait for Option
to Option conversion
Functions§
- iso8601
- Converts a timestamp in milliseconds to an ISO 8601 formatted string
- microseconds
- Returns the current time in microseconds since the Unix epoch
- milliseconds
- Returns the current time in milliseconds since the Unix epoch
- parse_
date - Parses a date string and returns the timestamp in milliseconds since Unix epoch
- parse_
iso8601 - Parses an ISO 8601 date string and returns the timestamp in milliseconds
- seconds
- Returns the current time in seconds since the Unix epoch
- ymd
- Alias for
yyyymmddfunction - ymdhms
- Formats a timestamp as “yyyy-MM-dd HH:mm:ss”
- yymmdd
- Formats a timestamp as “yy-MM-dd”
- yyyymmdd
- Formats a timestamp as “yyyy-MM-dd”