mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
feat(mustache): apply_format now accepts timezone info.
This commit is contained in:
+26
-2
@@ -228,7 +228,15 @@ apply_filter :: proc(value: any, filter: ^Pipe_Filter, pos: int, ctx: []any) ->
|
||||
date_format = df
|
||||
}
|
||||
|
||||
str2, err := apply_format(str, filter.args[:], pos, date_format)
|
||||
// Resolve timezone (optional — empty is fine, means display as-is)
|
||||
tz_name := ""
|
||||
if raw := resolve_name("timezone", ctx); raw != nil {
|
||||
if s, s_ok := reflect.as_string(raw); s_ok {
|
||||
tz_name = s
|
||||
}
|
||||
}
|
||||
|
||||
str2, err := apply_format(str, filter.args[:], pos, date_format, tz_name)
|
||||
if err != nil {
|
||||
return value, err
|
||||
} else {
|
||||
@@ -249,6 +257,7 @@ apply_format :: proc(
|
||||
args: []string,
|
||||
pos: int,
|
||||
date_format: string,
|
||||
timezone_name: string,
|
||||
) -> (
|
||||
result: string,
|
||||
err: Error,
|
||||
@@ -270,7 +279,22 @@ apply_format :: proc(
|
||||
}
|
||||
}
|
||||
|
||||
log.debugf("date: '%s' format: '%s'", iso, date_format)
|
||||
target_tz, tz_ok := get_cached_tz(timezone_name)
|
||||
if !tz_ok {
|
||||
return "", Error_Body {
|
||||
msg = fmt.tprintf("unable to load timezone '%s'", timezone_name),
|
||||
pos = pos,
|
||||
kind = .Data,
|
||||
}
|
||||
}
|
||||
|
||||
if target_tz != nil {
|
||||
components, _ = convert_to_tz(components, target_tz)
|
||||
} else if components.has_offset {
|
||||
components.tz_abbr = format_offset(components.offset_seconds)
|
||||
}
|
||||
|
||||
log.debugf("date: '%s' format: '%s' tz: '%s'", iso, date_format, timezone_name)
|
||||
return format_date(components, fmt_str), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user