nautilus_core/ffi/
datetime.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use std::ffi::c_char;
17
18use crate::{
19    datetime::{unix_nanos_to_iso8601, unix_nanos_to_iso8601_millis},
20    ffi::string::str_to_cstr,
21};
22
23/// Converts a UNIX nanoseconds timestamp to an ISO 8601 (RFC 3339) format C string pointer.
24#[cfg(feature = "ffi")]
25#[no_mangle]
26pub extern "C" fn unix_nanos_to_iso8601_cstr(timestamp_ns: u64) -> *const c_char {
27    str_to_cstr(&unix_nanos_to_iso8601(timestamp_ns.into()))
28}
29
30/// Converts a UNIX nanoseconds timestamp to an ISO 8601 (RFC 3339) format C string pointer
31/// with millisecond precision.
32#[cfg(feature = "ffi")]
33#[no_mangle]
34pub extern "C" fn unix_nanos_to_iso8601_millis_cstr(timestamp_ns: u64) -> *const c_char {
35    str_to_cstr(&unix_nanos_to_iso8601_millis(timestamp_ns.into()))
36}