Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
clickingbuttons committed Apr 27, 2024
0 parents commit 0b748e1
Show file tree
Hide file tree
Showing 13 changed files with 891 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/publish_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Docs

on:
push:
branches: ["master"]
workflow_dispatch:

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: true

jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Pages
uses: actions/configure-pages@v2
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.11.0
- run: zig build-lib src/root.zig -femit-docs=docs -fno-emit-bin
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: 'docs'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Tests

on:
push:
branches: ["master"]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.12.0
- run: zig build test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.gdb_history
zig-cache/
zig-out/
docs/
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright © 2023 clickingbuttons

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# datetime

![zig-version](https://img.shields.io/badge/dynamic/yaml?url=https%3A%2F%2Fraw.githubusercontent.com%2Fclickingbuttons%2Fdatetime%2Fmaster%2F.github%2Fworkflows%2Ftest.yml&query=%24.jobs.test.steps%5B1%5D.with.version&label=zig-version)
![tests](https://github.com/clickingbuttons/datetime/actions/workflows/test.yml/badge.svg)
[![docs](https://github.com/clickingbuttons/datetime/actions/workflows/publish_docs.yml/badge.svg)](https://clickingbuttons.github.io/datetime)

Generic Date, Time, and DateTime library.

Features:
- Convert to/from epoch subseconds using fastest known algorithm [^1].
- Specify your own epoch.
- Choose your own year and subsecond types.
- Durations.
- [ ] Timezones
- [ ] RFC3339
- [ ] Localization
- [ ] Leap seconds

## Why yet another date time library?
- There are uses for different year, subsecond precisions, and time offset precision.
- There are uses for different epochs.

[^1]: Epoch conversion implemented using [Euclidean Affine Functions by Cassio and Neri.](https://arxiv.org/pdf/2102.06959)
25 changes: 25 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const std = @import("std");

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const lib = b.addStaticLibrary(.{
.name = "datetime",
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});

b.installArtifact(lib);

const lib_unit_tests = b.addTest(.{
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);

const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
}
11 changes: 11 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.{
.name = "datetime",
.version = "0.0.1",
.paths = .{
"build.zig",
"build.zig.zon",
"src",
"LICENSE",
"README.md",
},
}
7 changes: 7 additions & 0 deletions src/date.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const gregorian = @import("./date/gregorian.zig");
pub const Gregorian = gregorian.Gregorian;
pub const GregorianAdvanced = gregorian.Advanced;

test {
_ = gregorian;
}
41 changes: 41 additions & 0 deletions src/date/epoch.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const std = @import("std");

pub const ComptimeDate = struct {
year: comptime_int,
month: Month,
day: Day,

pub const Month = std.math.IntFittingRange(1, 12);
pub const Day = std.math.IntFittingRange(1, 31);

pub fn init(year: comptime_int, month: Month, day: Day) ComptimeDate {
return .{ .year = year, .month = month, .day = day };
}
};

pub const posix = ComptimeDate.init(1970, 1, 1);
pub const dos = ComptimeDate.init(1980, 1, 1);
pub const ios = ComptimeDate.init(2001, 1, 1);
pub const openvms = ComptimeDate.init(1858, 11, 17);
pub const windows = ComptimeDate.init(1601, 1, 1);
pub const amiga = ComptimeDate.init(1978, 1, 1);
pub const pickos = ComptimeDate.init(1967, 12, 31);
pub const gps = ComptimeDate.init(1980, 1, 6);
pub const clr = ComptimeDate.init(1, 1, 1);
pub const uefi = ComptimeDate.init(1582, 10, 15);
pub const efi = ComptimeDate.init(1900, 1, 1);

pub const unix = posix;
pub const android = posix;
pub const os2 = dos;
pub const bios = dos;
pub const vfat = dos;
pub const ntfs = windows;
pub const zos = efi;
pub const ntp = zos;
pub const jbase = pickos;
pub const aros = amiga;
pub const morphos = amiga;
pub const brew = gps;
pub const atsc = gps;
pub const go = clr;
Loading

0 comments on commit 0b748e1

Please sign in to comment.