// Copyright (C) 2017-2018, 2020-2021 Luke Shumaker // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . package libfastimport import ( "fmt" "strconv" "strings" "time" "github.com/pkg/errors" ) // Ident is a tuple of a commiter's (or author's) name, email, and a // timestamp with timezone. // // BUG(lukeshu): Ident (and ParseIdent) only supports the // "raw"/"raw-permissive" date format (not "rfc2822" or "now") type Ident struct { Name string Email string Time time.Time } func (ut Ident) String() string { if ut.Name == "" { return fmt.Sprintf("<%s> %d %s", ut.Email, ut.Time.Unix(), ut.Time.Format("-0700")) } else { return fmt.Sprintf("%s <%s> %d %s", ut.Name, ut.Email, ut.Time.Unix(), ut.Time.Format("-0700")) } } // ParseIdent parses a string containing an Ident. // // The format of this string is // // SP LT GT SP