Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header for nested time.Time field is incorrect #245

Open
sgtsquiggs opened this issue Mar 7, 2023 · 1 comment
Open

Header for nested time.Time field is incorrect #245

sgtsquiggs opened this issue Mar 7, 2023 · 1 comment

Comments

@sgtsquiggs
Copy link

See example here: https://go.dev/play/p/LPHV70Rc8KP

package main

import (
	"fmt"
	"time"

	"github.com/gocarina/gocsv"
)

type Nested struct {
	UpdatedAt *time.Time `csv:"updated_at"`
}

type Row struct {
	Name string `csv:"name"`
	Data Nested `csv:"data"`
}

func main() {
	now := time.Now()
	dat := []Row{{Name: "matthew", Data: Nested{UpdatedAt: &now}}}
	csv, err := gocsv.MarshalString(dat)
	if err != nil {
		panic(fmt.Sprintf("marshal failed: %v", err))
	}
	fmt.Println(csv)
}

Expected:

name,data.updated_at
matthew,2009-11-10T23:00:00Z

Got:

name,data.UpdatedAt
matthew,2009-11-10T23:00:00Z
@haton14
Copy link
Contributor

haton14 commented Mar 26, 2023

@sgtsquiggs

I fixed it. Please check it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants