Files
Chase CichorzandClaude Opus 5.5 8e0ac3b258 Build the Tentacle SDK without cgo
The SDK reaches internal/datetime through settings validation, and that
package had only a cgo strftime implementation, so statically linked
Tentacle packages could not build. Split the locale-aware cgo formatter
into its own file and add a C-locale fallback for builds without cgo.
The reader itself still uses the cgo implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 16:06:38 -05:00

45 lines
953 B
Go

// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
//go:build cgo
package datetime
/*
#include <locale.h>
#include <stdlib.h>
#include <time.h>
*/
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))
}