The vaqt package offers data types and functions for handling time and duration in C, with nanosecond precision. Works with C99 (C11 is recommended on Windows for higher precision).
Concepts • Features • Getting started • Building from source • API reference
The package works with two types of values: Time and Duration.
Time is a pair (seconds, nanoseconds), where seconds is the 64-bit number of seconds since zero time (0001-01-01 00:00:00 UTC) and nanoseconds is the number of nanoseconds within the current second (0-999999999). Time can represent dates billions of years in the past or future with nanosecond precision.
Time is always operated in UTC, but you can convert it from/to a specific timezone.
Duration is a 64-bit number of nanoseconds. It can represent values up to about 290 years.
The package provides functions for common date and time operations.
Creating time values:
Extracting time fields:
Unix time:
Calendar time:
Time comparison:
Time arithmetic:
Rounding:
Formatting:
Marshaling:
Check the API reference for more details.
To use vaqt in your C project:
-
Copy the src/vaqt.h header file and the source files (src/*.c) into your project's vaqt source folder.
-
Include the header in your source files:
-
Use the types and functions as described in the documentation.
-
Compile your project along with the vaqt source files. For example:
Build and test the package:
Run examples:
Contributions are welcome. For anything other than bug fixes, please open an issue first to discuss what you want to change.
Make sure to add or update tests as needed.
Created by Anton Zhiyanov.
Based on Go's stdlib time package, available under the BSD 3-Clause License.