Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

23 Commits

Repository files navigation

**attention I use the night version *

Zig Datetime

thank

![actions](frmdstryr/

Table of Contents

Usage

pubconstDte=@import("datetime").Date; // work date Y M DpubconstDtm=@import("datetime").DTime; // UTC chronologpubconsttmz=@import("timezones"); // Time zonesconstallocator=std.heap.page_allocator;
constdate=tryDte.create(2019, 12, 25);
constnext_year=date.shiftDays(7);
assert(next_year.year==2020);
assert(next_year.month==1);
assert(next_year.day==1);
constdatuday=try. now(tmz.Europe.Paris); // get milliTimestanp add timezones = YMD of day// In UTC milliTimestampconstnow=Dtm.now(tmz.Europe.Paris);
std.debug.print("formaChrono UTC : {s}\n",.{c.ChronoTime(allocator) catch"0" });
// formaChrono UTC : 2025-01-14T:11:25:37N:0491Z:000std.debug.print("formaChrono NUM : {d}\n",.{c.ChronoNum(allocator) catch0 });
// formaChrono NUM : 202501141125370491000

Notes


the time zone initialization process is performed once after each boot and only at the first function call. This is a principle used on the AS400 during OPDP (OPEN-DATA-SPACE).

This is a standard date processing library, plus a feature for SQL that supports a NULL zone.
See examples in the zig_sql project.

In SQL, there are two ways of handling dates:
“NULL”, e.g. invoicing not processed.

“0000-00-00” is not a valid date, it's just an indication, you shouldn't use it in your SQL.

The date becomes invalid, for example when a record is “deinit”.
Dte.DATE.dateOff(&dfacture), becomes “0000-00-00” its status changes to false.

Normally, if you don't fiddle with the date apart from retrieving twisted text,
there'll be no error, catch unreachable instead of tryv

To regenerate the timezone.zig file, run gensrc.sh from the create_timezones folder.
this file is generated from timedatectl

isBad The “isBad” function checks for consistent date completeness

If you use an uninitialized or already uninitialized field, or isBad this will trigger an @panic error. --> CRTL

To be dynamic, an LMDB file is generated at each reboot only if the readTimezone() function is used.

Time-zone processing in source file ./liboffset/timeoffset.zig

searchWeek” is a function that determines the number of weeks, the last week and the start of week 01.



Outils

FunctionDescriptionPub
checkLeapYearis Leap Year.
dayInYearNumber of days in the year.
daysInMonthNumber of days in the month.
daysBeforeYearNumber of days before Jan 1st of year.
daysBeforeMonthNumber of days of the month precedent.
isFileopenfileAbsolute lmdb.

DateTime

FunctionDescriptionPub
HardTimeChange of field attribute.
nowUTCTimestamp date in UTC ONLYx
nowTimeTimestamp date into Time-zonex
TimestampDate time reverse timestampx
NumTimeTimestamp date into time-zonex
stringTimeDate-time format stringx

Date

FunctionDescriptionPubPanicctrl
createCreate and validate the datex?
dateOffChange status OFF for work SQL = nullx
[isBadConsistency test of the date. [ *
copyReturn a copy of the datexxx
HardDateChange of field attribute.
nowDateReturns today's date into time-zone readTimezone()x
eqlcomparaisonxx
compcomparaisonxx
gtcomparaisonxx
gtecomparaisonxx
ltcomparaisonxx
ltecomparaisonxx
parseIsoParse date in format YYYY-MM-DDxx
parseFRParse date in format YYYY-MM-DDxx
parseUSParse date in format YYYY-MM-DDxx
stringReturn date in ISO format YYYY-MM-DD.x
stringFRReturn date in ISO format DD-MM-YYYY.x
stringUSReturn date in ISO format MM-DD-YYYY.x
getYearget yearx
getMonthget Monthx
getDayget Dayx
getWeekget Weekx
getWeekDayget WeekDayx
restOfdaysget restOfdaysx
isWeekendTest Week endx
isLeapYearis Leap Yearx
dayNumnumber of days.
daysMoreAdd daysxx
daysLessSub daysxx
yearsMoreAdd yearsxx
yearsLessSub yearsxx
quantiemeReturns the day number in the yearxx
dayZellerCalculation of day number with Sunday = 01....
searchWeekCalculation week.
fromOrdinalCreate a Date since 01-Jan-0001.x
toOrdinalReturn proleptic Gregorian ordinal.

Timezone

FunctionDescriptionPubPanic
abbrevDayReturn the abbreviation name of the dayx
nameDayReturn the of the dayx
abbrevMonthReturn the abbreviation name of the Monthx
abbrevDayReturn the abbreviation name of the dayx

Avancement

-2025-01-16 06:30 start projet date-time

-2025-01-16 15:01 add function switchMonths

-2025-01-30 04:47 Formatting @panic and modifying isBad() deleting assert()

-2025-02-25 20:08 Complete overhaul of the DATE model

-2025-02-25 20:08 Dynamic timezone set-up

-2025-02-25 20:08 Automatic creation of timezone.zig source code, via the module: Creat_timezones

-2025-02-25 20:08 LMDB database creation

-2025-02-25 20:08 module timeoffset

-2025-03-10 16:40 Resuming diagnostics with the better-understood 0.14.0 @src deciphering

-2025-03-14 16:10 module timeoffsetAdd arena-allocator , standardization with string and decimal

@panic

-2025-08.22 02:10 update zig 0.15.1


-2025-11.05 17:09 update zig 0.16.dev remove std.time.nanoTimestamp()

-2025-11.06 13:36 Modification after a request for help in the Zig forum, more standard module retrieve nanoseconde


-2025-11-18 17:00 regression Regression back to version 15.2

About

DATE and TIMESTAMP field management

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages