GithubHelp home page GithubHelp logo

fobersteiner / zdt Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 6.38 MB

Timezoned Datetime in Zig. For learning purposes.

Home Page: https://fobersteiner.github.io/zdt/

License: Mozilla Public License 2.0

Zig 96.59% Python 3.41%
datetime timezones zig ziglang zig-package date duration time

zdt's Introduction

zdt

Datetime with Timezones in Zig. Opinionated, and mostly for learning purposes.

Demo:

  var tz_LA = try zdt.Timezone.fromTzfile("America/Los_Angeles", allocator);
  defer tz_LA.deinit();
  var tz_Paris = try zdt.Timezone.fromTzfile("Europe/Paris", allocator);
  defer tz_Paris.deinit();

  const a_datetime = try zdt.stringIO.parseISO8601("2022-03-07");
  const this_time_LA = try a_datetime.tzLocalize(tz_LA);
  const this_time_Paris = try this_time_LA.tzConvert(tz_Paris);

  std.debug.print(
      "Time, LA : {s}\n... that's {s} in Paris\n",
      .{ this_time_LA, this_time_Paris },
  );
  // Time, LA : 2022-03-07T00:00:00-08:00
  // ... that's 2022-03-07T09:00:00+01:00 in Paris

  const wall_diff = try this_time_Paris.diffWall(this_time_LA);
  const abs_diff = this_time_Paris.diff(this_time_LA);

  std.debug.print(
      "Wall clock time difference: {s}\nAbsolute time difference: {s}\n",
      .{ wall_diff, abs_diff },
  );
  // Wall clock time difference: PT09H00M00S
  // Absolute time difference: PT00H00M00S

More examples in the ./examples directory. There's a build-step to build them all; EX:

zig build examples && ./zig-out/bin/ex_datetime

Documentation

Development

See changelog.

Zig version

This library is developed with Zig 0.14.0-dev, might not compile with older versions. As of 2024-08-07, Zig-0.13 stable or higher should work.

Dependencies

  • none

Time zone database

zdt comes with eggert/tz. The database is compiled and shipped with zdt (as-is; not tar-balled or compressed). If you wish to use your own version of the IANA time zone db, you can set a path to it using the -Dprefix-tzdb="path/to/your/tzdb" option. See also zig build --help

For development, to update the time zone database and the version info, run the following build steps: zig build update-tz-database && zig build update-tz-version.

License

MPL. See the LICENSE file in the root directory of the repository.

zdt's People

Contributors

fobersteiner avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.