imshooter/chrono-omp
An open.mp component for dates and times: timestamps and durations with tags, the calendar and time zones, with the names of pawn-chrono and faster in every call.
Adds its include files, with the libraries it depends on, to the Pawn compiler in your browser, ready to include in a script.
README.md
Chrono
[!NOTE] Chrono is experimental and already runs in production. Its natives may still change from one version to the next. It was made with Claude Opus 5.5, a model by Anthropic.
An open.mp component for dates and times: timestamps and durations with a tag for each unit, the calendar and time zones. It takes the place of the pawn-chrono plugin with the same names, and every call is faster.
Features
- Timestamps with tags, so
Now() + Days:3is aTimestampandTimestamp - TimestampgivesSeconds. - Time zones with daylight saving time. The server keeps one, named in
config.json, and every function that reads or writes a date takes another, as"UTC". - Writing and reading times with the specifiers of C++, as
%Y-%m-%d %H:%M:%S, with names always in English. - Durations read from text such as
1h 30m, and written in words or with a format of their own, as%H:%M:%S. - The calendar: the date, time and day of the week of a timestamp, a timestamp from a date, and months and years counted as the calendar does, so January 31st and one month is the last day of February.
Installation
- Download the latest release from Releases, the
windows-x86or thelinux-x86zip. - Place
Chrono.dllorChrono.soin thecomponentsfolder of the server. - Place
chrono.incin the include folder of the compiler. - Remove
chronofrompawn.legacy_plugins, as both give the same natives.
No plugin is needed. Tested with open.mp 1.6.7 on Windows, Ubuntu 20.04, Debian 12 and Ubuntu 24.04. The time zones come from Windows 10 version 1903 or later, and on Linux from the tzdata of the system. The Linux build needs glibc 2.25 or later.
Configuration
"chrono": {
"time_zone": "Europe/London"
}
| Key | Description |
|---|---|
time_zone | The zone of the server, by its name in the time zone database. Empty, the zone of the machine. |
A first script
#include <open.mp>
#include <chrono>
public OnPlayerConnect(playerid) {
new const
Timestamp:expiry = Now() + Days:30
;
new
date[32],
left[48]
;
TimeFormat(expiry, "%d %B %Y at %H:%M", date);
DurationFormat(expiry - Now(), left);
SendClientMessage(playerid, -1, "Your membership ends on %s, in %s.", date, left);
return 1;
}
Coming from pawn-chrono
Scripts compile as they are, and scripts built against pawn-chrono run on the component. What changes:
TimeParseandDurationParsereturntruewhen they read the text, where pawn-chrono returned0.TimeFormatwrites in the zone of the server, where pawn-chrono wrote UTC. Pass"UTC"to keep the old text.DayInHoursis24, not12, andDurationFormatno longer writes before its array for a duration of zero.MonthInMilliseconds, which did not fit a cell, is gone.
Performance
Microseconds per call, measured on one computer with pawn-chrono and chrono-omp on the same server and script:
| Call | pawn-chrono | chrono-omp |
|---|---|---|
Now | 0.03 | 0.03 |
TimeFormat | 3.4 | 0.33 to 0.46 |
TimeParse | 2.4 | 0.38 |
DurationParse | 0.66 | 0.32 |
DurationFormat | 0.77 | 0.25 |
Tests
tests/chronotest.pwn: writing and reading times, durations, the calendar and time zones, on a server inEurope/London. GitHub Actions runs it on open.mp for Linux at every push.
Building
CMake 3.19 or later fetches the open.mp SDK and the Pawn headers. The server is 32 bit, so the component must be too.
On Windows, with Visual Studio 2022 or its Build Tools:
cmake -S . -B build -A Win32
cmake --build build --config Release
On Linux, with GCC 13 or later and its 32 bit libraries:
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32 -DCMAKE_SHARED_LINKER_FLAGS=-m32
cmake --build build
The component is written to build/Release/Chrono.dll or build/Chrono.so. The Linux release is built on Ubuntu 20.04, as .github/workflows/main.yml does.
Thanks to
- @Southclaws for pawn-chrono, whose names, tags and constants Chrono keeps.
- @openmultiplayer for the SDK and the Pawn compiler.
License
Released under the MIT License. The names, tags and constants of chrono.inc come from pawn-chrono, under its own MIT License.
chronocomponentdateopen-mpopenmppawnsa-mpsamptimetimezone
This page is built from what GitHub publishes about the repository. samp.directory does not host the code. Report a problem with this listing