- Compiler: PP → Lexer → Parser → Analyzer → Gengo pipeline - Parser: 232/236 (98%) Harbour compatibility, registry-based dispatch - RTL: 351 Harbour-compatible functions - RDD: DBF/NTX/CDX engines with Rushmore bitmap optimization - Go Interop: IMPORT + pkg.Func() + obj:Method() with FastPath (15M calls/sec) - HB_FUNC API: Full Harbour C API compatible Go bridge - Concurrency: SPAWN/LAUNCH/GOROUTINE, <-, WATCH, PARALLEL FOR, ASYNC/AWAIT - Extensions: Multi-return, DEFER, Slice, f-string, Nil-safe ?:, CONST - Macro Compiler: Runtime AST parsing and evaluation - Debugger: TUI debugger with source display, breakpoints, stepping - FRB: Native + Pcode dual mode runtime binary - Tests: 13 packages ALL PASS Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
145 lines
3.2 KiB
Go
145 lines
3.2 KiB
Go
// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com)
|
|
// All rights reserved.
|
|
|
|
// Timestamp functions: HB_DATETIME, HB_TTOC, HB_CTOT, HB_HOUR, HB_MIN, HB_SEC,
|
|
// HB_TTOS, HB_STOT
|
|
|
|
package hbrtl
|
|
|
|
import (
|
|
"five/hbrt"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// HB_DATETIME([nYear, nMonth, nDay, nHour, nMin, nSec, nMSec]) → tTimestamp
|
|
func HbDateTime(t *hbrt.Thread) {
|
|
nParams := t.ParamCount()
|
|
t.Frame(nParams, 0)
|
|
defer t.EndProc()
|
|
|
|
now := time.Now()
|
|
if nParams >= 3 {
|
|
y := int(t.Local(1).AsNumInt())
|
|
m := time.Month(t.Local(2).AsNumInt())
|
|
d := int(t.Local(3).AsNumInt())
|
|
h, mi, s := 0, 0, 0
|
|
if nParams >= 4 {
|
|
h = int(t.Local(4).AsNumInt())
|
|
}
|
|
if nParams >= 5 {
|
|
mi = int(t.Local(5).AsNumInt())
|
|
}
|
|
if nParams >= 6 {
|
|
s = int(t.Local(6).AsNumInt())
|
|
}
|
|
now = time.Date(y, m, d, h, mi, s, 0, time.Local)
|
|
}
|
|
// Store as string representation for now
|
|
t.RetString(now.Format("2006-01-02 15:04:05"))
|
|
}
|
|
|
|
// HB_HOUR(tTimestamp|cTimeStr) → nHour
|
|
func HbHour(t *hbrt.Thread) {
|
|
t.Frame(1, 0)
|
|
defer t.EndProc()
|
|
s := t.Local(1).AsString()
|
|
parts := strings.Split(s, " ")
|
|
if len(parts) >= 2 {
|
|
timeParts := strings.Split(parts[1], ":")
|
|
if len(timeParts) >= 1 {
|
|
h, _ := strconv.Atoi(timeParts[0])
|
|
t.RetInt(int64(h))
|
|
return
|
|
}
|
|
}
|
|
t.RetInt(0)
|
|
}
|
|
|
|
// HB_MINUTE(tTimestamp|cTimeStr) → nMinute
|
|
func HbMinute(t *hbrt.Thread) {
|
|
t.Frame(1, 0)
|
|
defer t.EndProc()
|
|
s := t.Local(1).AsString()
|
|
parts := strings.Split(s, " ")
|
|
if len(parts) >= 2 {
|
|
timeParts := strings.Split(parts[1], ":")
|
|
if len(timeParts) >= 2 {
|
|
m, _ := strconv.Atoi(timeParts[1])
|
|
t.RetInt(int64(m))
|
|
return
|
|
}
|
|
}
|
|
t.RetInt(0)
|
|
}
|
|
|
|
// HB_SEC(tTimestamp|cTimeStr) → nSecond
|
|
func HbSec(t *hbrt.Thread) {
|
|
t.Frame(1, 0)
|
|
defer t.EndProc()
|
|
s := t.Local(1).AsString()
|
|
parts := strings.Split(s, " ")
|
|
if len(parts) >= 2 {
|
|
timeParts := strings.Split(parts[1], ":")
|
|
if len(timeParts) >= 3 {
|
|
sec, _ := strconv.Atoi(timeParts[2])
|
|
t.RetInt(int64(sec))
|
|
return
|
|
}
|
|
}
|
|
t.RetInt(0)
|
|
}
|
|
|
|
// HB_TTOC(tTimestamp [, cFormat]) → cString
|
|
func HbTToC(t *hbrt.Thread) {
|
|
nParams := t.ParamCount()
|
|
t.Frame(nParams, 0)
|
|
defer t.EndProc()
|
|
t.RetString(t.Local(1).AsString())
|
|
}
|
|
|
|
// HB_CTOT(cString) → tTimestamp
|
|
func HbCToT(t *hbrt.Thread) {
|
|
t.Frame(1, 0)
|
|
defer t.EndProc()
|
|
t.RetString(t.Local(1).AsString())
|
|
}
|
|
|
|
// HB_TTOS(tTimestamp) → cString (YYYYMMDDHHMMSS)
|
|
func HbTToS(t *hbrt.Thread) {
|
|
t.Frame(1, 0)
|
|
defer t.EndProc()
|
|
s := t.Local(1).AsString()
|
|
s = strings.ReplaceAll(s, "-", "")
|
|
s = strings.ReplaceAll(s, ":", "")
|
|
s = strings.ReplaceAll(s, " ", "")
|
|
t.RetString(s)
|
|
}
|
|
|
|
// HB_STOT(cString) → tTimestamp
|
|
func HbSToT(t *hbrt.Thread) {
|
|
t.Frame(1, 0)
|
|
defer t.EndProc()
|
|
s := t.Local(1).AsString()
|
|
if len(s) >= 14 {
|
|
formatted := fmt.Sprintf("%s-%s-%s %s:%s:%s",
|
|
s[0:4], s[4:6], s[6:8], s[8:10], s[10:12], s[12:14])
|
|
t.RetString(formatted)
|
|
} else {
|
|
t.RetString(s)
|
|
}
|
|
}
|
|
|
|
// HB_MILLISECONDS() → nMilliseconds (since midnight)
|
|
func HbMilliseconds(t *hbrt.Thread) {
|
|
t.Frame(0, 0)
|
|
defer t.EndProc()
|
|
now := time.Now()
|
|
midnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
|
|
t.RetLong(now.Sub(midnight).Milliseconds())
|
|
}
|
|
|
|
var _ = fmt.Sprintf // keep import
|