// Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // SPDX-License-Identifier: GPL-3.0-or-later //go:build cgo package datetime /* #include #include #include */ import "C" import ( "time" "unsafe" ) func init() { locale := C.CString("") defer C.free(unsafe.Pointer(locale)) C.setlocale(C.LC_TIME, locale) } func format(now time.Time, spec string) string { cSpec := C.CString(spec) defer C.free(unsafe.Pointer(cSpec)) tm := C.struct_tm{ tm_year: C.int(now.Year() - 1900), tm_mon: C.int(int(now.Month()) - 1), tm_mday: C.int(now.Day()), tm_hour: C.int(now.Hour()), tm_min: C.int(now.Minute()), tm_sec: C.int(now.Second()), tm_wday: C.int(int(now.Weekday())), tm_yday: C.int(now.YearDay() - 1), tm_isdst: -1, } buffer := make([]C.char, 512) length := C.strftime(&buffer[0], C.size_t(len(buffer)), cSpec, &tm) return C.GoStringN(&buffer[0], C.int(length)) }