samp.directory
← Scripts et bibliothèques

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.

Plugin★ 0mis à jour il y a 3 heuresMITC++
Ouvrir sur GitHub
L’essayer dans le compilateur Pawn →

Ajoute ses fichiers include, avec les bibliothèques dont il dépend, au compilateur Pawn de ton navigateur, prêts à être inclus dans un 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:3 is a Timestamp and Timestamp - Timestamp gives Seconds.
  • 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

  1. Download the latest release from Releases, the windows-x86 or the linux-x86 zip.
  2. Place Chrono.dll or Chrono.so in the components folder of the server.
  3. Place chrono.inc in the include folder of the compiler.
  4. Remove chrono from pawn.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"
}
KeyDescription
time_zoneThe 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:

  • TimeParse and DurationParse return true when they read the text, where pawn-chrono returned 0.
  • TimeFormat writes in the zone of the server, where pawn-chrono wrote UTC. Pass "UTC" to keep the old text.
  • DayInHours is 24, not 12, and DurationFormat no 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:

Callpawn-chronochrono-omp
Now0.030.03
TimeFormat3.40.33 to 0.46
TimeParse2.40.38
DurationParse0.660.32
DurationFormat0.770.25

Tests

  • tests/chronotest.pwn: writing and reading times, durations, the calendar and time zones, on a server in Europe/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

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

Cette page est construite à partir de ce que GitHub publie sur le dépôt. samp.directory n’héberge pas le code. Signaler un problème avec cette fiche

imshooter/chrono-omp : Plugin SA-MP | samp.directory