Skip to content

Commit cf1015b

Browse files
committed
maj_20250313-16:30
1 parent 94a6996 commit cf1015b

File tree

4 files changed

+133
-105
lines changed

4 files changed

+133
-105
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,10 @@ searchWeek” is a function that determines the number of weeks, the last week a
191191

192192
-2025-02-25 20:08 module timeoffset <br/>
193193

194-
-2025-03-10 16:40 Resuming diagnostics with the better-understood 0.14.0 @src deciphering @panic <br/>
194+
-2025-03-10 16:40 Resuming diagnostics with the better-understood 0.14.0 @src deciphering
195+
196+
-2025-03-14 16:10 module timeoffsetAdd arena-allocator , standardization with string and decimal <br/>
197+
198+
199+
@panic <br/>
195200

libdate/datetime/datetime.zig

+57-41
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const lib_file ="/tmp/Timezone/data.mdb";
1313

1414
const AllocDate = std.mem.Allocator;
1515
const Order = std.math.Order;
16-
const allocDT = std.heap.page_allocator;
1716

1817

1918
pub const MIN_YEAR: u16 = 1;
@@ -33,6 +32,14 @@ var udate: DATE = undefined;
3332
Failed_value,
3433
};
3534

35+
36+
37+
38+
39+
var arenaDate = std.heap.ArenaAllocator.init(std.heap.page_allocator);
40+
var allocDate = arenaDate.allocator();
41+
var arenaDtime = std.heap.ArenaAllocator.init(std.heap.page_allocator);
42+
var allocDtime = arenaDtime.allocator();
3643
//----------------------------------
3744
// outils
3845
//----------------------------------
@@ -83,6 +90,11 @@ pub const DTIME = struct {
8390
nanosecond: u64 = 0,// 0> 999999999
8491
tmz : i16 = 0,
8592

93+
pub fn deinitAlloc() void {
94+
arenaDtime.deinit();
95+
arenaDtime = std.heap.ArenaAllocator.init(std.heap.page_allocator);
96+
allocDtime = arenaDtime.allocator();
97+
}
8698
//Change of field attribute
8799
pub fn hardTime(buf :[]const u8, ntmz :i32) DTIME{
88100

@@ -174,11 +186,11 @@ pub const DTIME = struct {
174186

175187
const day: u64 = days_since_epoch + 1;
176188
const chronoHardFMT :[]const u8 = "{:0>4}{:0>2}{:0>2}{:0>2}{:0>2}{:0>2}{:0>9}";
177-
const r : []const u8 = std.fmt.allocPrint(allocDT, chronoHardFMT,
189+
const r : []const u8 = std.fmt.allocPrint(allocDate, chronoHardFMT,
178190
.{ year, month, day , hr, min,sec,ns}) catch unreachable;
179191

180192
const tm = hardTime(r, 0) ;
181-
defer allocDT.free(r);
193+
defer allocDate.free(r);
182194
return tm;
183195
}
184196

@@ -250,32 +262,32 @@ pub const DTIME = struct {
250262
const day: u64 = days_since_epoch + 1;
251263

252264
const chronoHardFMT :[]const u8 = "{:0>4}{:0>2}{:0>2}{:0>2}{:0>2}{:0>2}{:0>9}";
253-
const r : []const u8 = std.fmt.allocPrint(allocDT, chronoHardFMT,
265+
const r : []const u8 = std.fmt.allocPrint(allocDtime, chronoHardFMT,
254266
.{ year, month, day , hr, min,sec,ns}) catch unreachable;
255267

256268
const tm = hardTime(r, offset) ;
257-
defer allocDT.free(r);
269+
defer allocDtime.free(r);
258270
return tm;
259271
}
260272

261273

262274
// Date-time formatting
263275
const chronoTimeFMT :[]const u8 = "{:0>4}-{:0>2}-{:0>2}T:{:0>2}:{:0>2}:{:0>2}N:{:0>9}Z:{d}";
264276

265-
pub fn stringTime(self: DTIME, allocat: AllocDate) []const u8 {
266-
return std.fmt.allocPrint(allocat, chronoTimeFMT,
277+
pub fn stringTime(self: DTIME) []const u8 {
278+
return std.fmt.allocPrint(allocDtime, chronoTimeFMT,
267279
.{ self.year, self.month, self.day, self.hour, self.minute,self.second,self.nanosecond,self.tmz })
268280
catch unreachable;
269281
}
270282

271283
const chronoNumFMT = "{:0>4}{:0>2}{:0>2}{:0>2}{:0>2}{:0>2}{:0>9}{d}";
272284

273-
pub fn numTime(self: DTIME, allocat: AllocDate) u128 {
274-
const r : []const u8 = std.fmt.allocPrint(allocat, chronoNumFMT,
285+
pub fn numTime(self: DTIME) u128 {
286+
const r : []const u8 = std.fmt.allocPrint(allocDtime, chronoNumFMT,
275287
.{ self.year, self.month, self.day, self.hour, self.minute,self.second,self.nanosecond,self.tmz })
276288
catch unreachable;
277289
const i :u128 = std.fmt.parseInt(u128,r,10) catch unreachable;
278-
defer allocat.free(r);
290+
defer allocDtime.free(r);
279291
return i;
280292

281293
}
@@ -294,7 +306,11 @@ pub const DATE = struct {
294306
week: u6, // Week of year 1-53
295307
status : bool = false, // date null
296308

297-
309+
pub fn deinitAlloc() void {
310+
arenaDate.deinit();
311+
arenaDate = std.heap.ArenaAllocator.init(std.heap.page_allocator);
312+
allocDate = arenaDate.allocator();
313+
}
298314

299315
// Create and validate the date
300316
pub fn create(year: u32, month: u32, day: u32) !DATE {
@@ -354,7 +370,7 @@ pub const DATE = struct {
354370
pub fn copy(self: DATE) !DATE {
355371
if (!isBad(self)) {
356372
const s = @src();
357-
@panic( std.fmt.allocPrint(allocDT,
373+
@panic( std.fmt.allocPrint(allocDate,
358374
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
359375
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
360376
catch unreachable);
@@ -427,9 +443,9 @@ pub const DATE = struct {
427443

428444

429445
const chronoHardFMT :[]const u8 = "{:0>4}{:0>2}{:0>2}";
430-
const r : []const u8 = std.fmt.allocPrint(allocDT, chronoHardFMT,
446+
const r : []const u8 = std.fmt.allocPrint(allocDate, chronoHardFMT,
431447
.{ year, month, day }) catch unreachable;
432-
defer allocDT.free(r);
448+
defer allocDate.free(r);
433449

434450
var datx = hardDate(r);
435451
datx.weekday = @intCast(dayNum(datx)); datx.week = @intCast(searchWeek(datx));
@@ -443,7 +459,7 @@ pub const DATE = struct {
443459
pub fn eql(self: DATE, other: DATE) bool {
444460
if (!isBad(self)) {
445461
const s = @src();
446-
@panic( std.fmt.allocPrint(allocDT,
462+
@panic( std.fmt.allocPrint(allocDate,
447463
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
448464
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
449465
catch unreachable);
@@ -454,7 +470,7 @@ pub const DATE = struct {
454470
pub fn cmp(self: DATE, other: DATE) Order {
455471
if (!isBad(self)) {
456472
const s = @src();
457-
@panic( std.fmt.allocPrint(allocDT,
473+
@panic( std.fmt.allocPrint(allocDate,
458474
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
459475
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
460476
catch unreachable);
@@ -471,7 +487,7 @@ pub const DATE = struct {
471487
pub fn gt(self: DATE, other: DATE) bool {
472488
if (!isBad(self)) {
473489
const s = @src();
474-
@panic( std.fmt.allocPrint(allocDT,
490+
@panic( std.fmt.allocPrint(allocDate,
475491
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
476492
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
477493
catch unreachable);
@@ -481,7 +497,7 @@ pub const DATE = struct {
481497
pub fn gte(self: DATE, other: DATE) bool {
482498
if (!isBad(self)) {
483499
const s = @src();
484-
@panic( std.fmt.allocPrint(allocDT,
500+
@panic( std.fmt.allocPrint(allocDate,
485501
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
486502
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
487503
catch unreachable);
@@ -492,7 +508,7 @@ pub const DATE = struct {
492508
pub fn lt(self: DATE, other: DATE) bool {
493509
if (!isBad(self)) {
494510
const s = @src();
495-
@panic( std.fmt.allocPrint(allocDT,
511+
@panic( std.fmt.allocPrint(allocDate,
496512
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
497513
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
498514
catch unreachable);
@@ -502,7 +518,7 @@ pub const DATE = struct {
502518
pub fn lte(self: DATE, other: DATE) bool {
503519
if (!isBad(self)) {
504520
const s = @src();
505-
@panic( std.fmt.allocPrint(allocDT,
521+
@panic( std.fmt.allocPrint(allocDate,
506522
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
507523
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
508524
catch unreachable);
@@ -547,43 +563,43 @@ pub const DATE = struct {
547563

548564
// Return date in ISO format YYYY-MM-DD
549565
const ISO_DATE_FMT = "{:0>4}-{:0>2}-{:0>2}";
550-
pub fn string(self: DATE, allocator: AllocDate) []const u8 {
566+
pub fn string(self: DATE) []const u8 {
551567
if (!isBad(self)) {
552568
const s = @src();
553-
@panic( std.fmt.allocPrint(allocDT,
569+
@panic( std.fmt.allocPrint(allocDate,
554570
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
555571
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
556572
catch unreachable);
557573
}
558-
return std.fmt.allocPrint(allocator, ISO_DATE_FMT,
574+
return std.fmt.allocPrint(allocDate, ISO_DATE_FMT,
559575
.{ self.year, self.month, self.day }) catch unreachable;
560576
}
561577

562578
// Return date in FR format DD/MM/YYYY
563579
const FR_DATE_FMT = "{:0>2}/{:0>2}/{:0>4}";
564-
pub fn stringFR(self: DATE, allocator: AllocDate) []const u8 {
580+
pub fn stringFR(self: DATE) []const u8 {
565581
if (!isBad(self)) {
566582
const s = @src();
567-
@panic( std.fmt.allocPrint(allocDT,
583+
@panic( std.fmt.allocPrint(allocDate,
568584
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
569585
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
570586
catch unreachable);
571587
}
572-
return std.fmt.allocPrint(allocator, FR_DATE_FMT,
588+
return std.fmt.allocPrint(allocDate, FR_DATE_FMT,
573589
.{ self.day, self.month, self.year }) catch unreachable;
574590
}
575591

576592
// Return date in FR format MM/DD/YYYY
577593
const US_DATE_FMT = "{:0>2}/{:0>2}/{:0>4}";
578-
pub fn stringUS(self: DATE, allocator: AllocDate) []const u8 {
594+
pub fn stringUS(self: DATE) []const u8 {
579595
if (!isBad(self)) {
580596
const s = @src();
581-
@panic( std.fmt.allocPrint(allocDT,
597+
@panic( std.fmt.allocPrint(allocDate,
582598
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
583599
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
584600
catch unreachable);
585601
}
586-
return std.fmt.allocPrint(allocator, US_DATE_FMT,
602+
return std.fmt.allocPrint(allocDate, US_DATE_FMT,
587603
.{ self.month, self.day, self.year }) catch unreachable;
588604
}
589605

@@ -641,7 +657,7 @@ pub const DATE = struct {
641657
ctrl.year = self.year; ctrl.month = self.month; ctrl.day = self.day; ctrl.status = self.status;
642658
if (!isBadx(self)) {
643659
const s = @src();
644-
@panic( std.fmt.allocPrint(allocDT,
660+
@panic( std.fmt.allocPrint(allocDate,
645661
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
646662
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
647663
catch unreachable);
@@ -662,7 +678,7 @@ pub const DATE = struct {
662678
pub fn daysLess(self: *DATE, days: u32) bool {
663679
if (!isBadx(self)) {
664680
const s = @src();
665-
@panic( std.fmt.allocPrint(allocDT,
681+
@panic( std.fmt.allocPrint(allocDate,
666682
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
667683
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
668684
catch unreachable);
@@ -684,7 +700,7 @@ pub const DATE = struct {
684700
pub fn yearsMore(self: *DATE, year: u32) bool {
685701
if (!isBadx(self)) {
686702
const s = @src();
687-
@panic( std.fmt.allocPrint(allocDT,
703+
@panic( std.fmt.allocPrint(allocDate,
688704
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
689705
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
690706
catch unreachable);
@@ -709,7 +725,7 @@ pub const DATE = struct {
709725
pub fn yearsLess(self: *DATE, year: u32) bool {
710726
if (!isBadx(self)) {
711727
const s = @src();
712-
@panic( std.fmt.allocPrint(allocDT,
728+
@panic( std.fmt.allocPrint(allocDate,
713729
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
714730
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
715731
catch unreachable);
@@ -736,7 +752,7 @@ pub const DATE = struct {
736752
(self.month < 1 or self.month > 12) or
737753
(self.day < 1 or self.day > daysInMonth(self.year, self.month)) ) {
738754
const s = @src();
739-
@panic( std.fmt.allocPrint(allocDT,
755+
@panic( std.fmt.allocPrint(allocDate,
740756
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
741757
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
742758
catch unreachable);
@@ -906,7 +922,7 @@ pub const DATE = struct {
906922

907923
if ( ord > MAX_ORDINAL){
908924
const s = @src();
909-
@panic( std.fmt.allocPrint(allocDT,
925+
@panic( std.fmt.allocPrint(allocDate,
910926
"\n\n\r file:{s} line:{d} column:{d} func:{s}({d}) ordinal out-of-service err:{}\n\r"
911927
,.{s.file, s.line, s.column,s.fn_name,ord,Error.Failed_zone})
912928
catch unreachable);
@@ -959,28 +975,28 @@ pub const DATE = struct {
959975

960976
// Return date extended
961977
const DATE_FMT_EXT= "{s} {:0>2} {s} {:0>4}";
962-
pub fn dateExt(self: DATE, allocator: AllocDate, lng: Idiom) []u8 {
978+
pub fn dateExt(self: DATE, lng: Idiom) []u8 {
963979
if (!isBad(self)) {
964980
const s = @src();
965-
@panic( std.fmt.allocPrint(allocDT,
981+
@panic( std.fmt.allocPrint(allocDate,
966982
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
967983
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
968984
catch unreachable);
969985
}
970-
return std.fmt.allocPrint(allocator, DATE_FMT_EXT,
986+
return std.fmt.allocPrint(allocDate, DATE_FMT_EXT,
971987
.{ Idiom.nameDay(self.weekday,lng), self.day,Idiom.nameMonth(self.month,lng), self.year }) catch unreachable;
972988
}
973989

974990
const DATE_FMT_ABR= "{s}. {:0>2} {s}. {:0>4}";
975-
pub fn dateAbr(self: DATE, allocator: AllocDate, lng: Idiom) []u8 {
991+
pub fn dateAbr(self: DATE, lng: Idiom) []u8 {
976992
if (!isBad(self)) {
977993
const s = @src();
978-
@panic( std.fmt.allocPrint(allocDT,
994+
@panic( std.fmt.allocPrint(allocDate,
979995
"\n\n\r file:{s} line:{d} column:{d} func:{s} out-of-service err:{} >>{d}-{d}-{d}\n\r"
980996
,.{s.file, s.line, s.column,s.fn_name,Error.Failed_zone, self.year, self.month, self.day})
981997
catch unreachable);
982998
}
983-
return std.fmt.allocPrint(allocator, DATE_FMT_ABR,
999+
return std.fmt.allocPrint(allocDate, DATE_FMT_ABR,
9841000
.{ Idiom.abbrevDay(self.weekday,lng), self.day, Idiom.abbrevMonth(self.month,lng), self.year }) catch unreachable;
9851001
}
9861002

0 commit comments

Comments
 (0)