← Library TimeDeterministic

CityTimeOp

Returns the current local time for a supported city in RFC3339 format.

Inputs

FieldTypeDescription
City*stringCity name — must be "New York" or "Tokyo"

Outputs

FieldTypeDescription
ResultstringRFC3339 formatted local time for the city

Supported cities: New York, Tokyo. Passing an unsupported city name returns an error. Use IfStringEqOp upstream to guard against unknown city values.

Typical Use Cases

  • Timezone-aware workflow decisions
  • Displaying time in a user's local timezone
  • Time-of-day routing (business hours check)

Complete Runnable Example

Fetches the current local time in Tokyo in RFC3339 format for a timezone-aware workflow.

main.go
package main

import (
	"context"
	"encoding/json"
	"log"
	"os"
	"time"

	"github.com/akennis/sparsi-go/library"
	_ "github.com/akennis/dagor/operator/builtin"

	"github.com/panjf2000/ants/v2"
	"github.com/akennis/dagor"
	"github.com/akennis/dagor/graph"
)

func main() {
	city := "Tokyo"
	library.RegisterConst("city_val", city)

	g, err := graph.NewBuilder("citytime_demo").
		Vertex("src").Op("city_val").Output("Result", "wire_city").
		Vertex("ct").Op("CityTimeOp").
		Input("City", "wire_city").
		Output("Result", "local_time").
		Build()
	if err != nil {
		log.Fatalf("build: %v", err)
	}

	pool, err := ants.NewPool(4)
	if err != nil {
		log.Fatalf("pool: %v", err)
	}
	defer pool.Release()

	eng, err := dagor.NewEngine(g, pool)
	if err != nil {
		log.Fatalf("engine: %v", err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
	defer cancel()

	if err := eng.Run(ctx); err != nil {
		log.Fatalf("run: %v", err)
	}

	out := map[string]any{"city": city}
	if raw, ok := eng.GetOutput("local_time"); ok {
		out["local_time"] = *raw.(*string)
	}
	enc := json.NewEncoder(os.Stdout)
	enc.SetIndent("", "  ")
	enc.Encode(out)
}