File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ package markdown
2+
3+ import (
4+ "time"
5+
6+ "github.com/grokify/mogo/time/timeutil"
7+ )
8+
9+ func GeneratedAtLocationStringsHuman (dt time.Time , locNames []string ) (string , error ) {
10+ return GeneratedAtLocationStrings (timeutil .HumanDateTime , dt , locNames )
11+ }
12+
13+ func GeneratedAtLocationStrings (layout string , dt time.Time , locNames []string ) (string , error ) {
14+ locs := []* time.Location {}
15+ for _ , locStr := range locNames {
16+ if loc , err := time .LoadLocation (locStr ); err != nil {
17+ return "" , err
18+ } else if loc != nil {
19+ locs = append (locs , loc )
20+ }
21+ }
22+ return GeneratedAt (layout , dt , locs ), nil
23+ }
24+
25+ func GeneratedAt (layout string , dt time.Time , locs []* time.Location ) string {
26+ prefix := "Generated at"
27+ if len (locs ) == 0 {
28+ return prefix + " " + dt .Format (layout )
29+ } else if len (locs ) == 1 {
30+ if locs [0 ] != nil {
31+ dt = dt .In (locs [0 ])
32+ }
33+ return prefix + " " + dt .Format (layout )
34+ }
35+ str := prefix + "\n "
36+ for _ , loc := range locs {
37+ if loc != nil {
38+ dt = dt .In (loc )
39+ }
40+ str += "* " + dt .Format (layout ) + "\n "
41+ }
42+ return str
43+ }
You can’t perform that action at this time.
0 commit comments