TimeFormat converts a user-supplied string to a Go time constant, if possible
(timeFormat string)
| 335 | |
| 336 | // TimeFormat converts a user-supplied string to a Go time constant, if possible |
| 337 | func TimeFormat(timeFormat string) string { |
| 338 | switch timeFormat { |
| 339 | case "Layout": |
| 340 | timeFormat = time.Layout |
| 341 | case "ANSIC": |
| 342 | timeFormat = time.ANSIC |
| 343 | case "UnixDate": |
| 344 | timeFormat = time.UnixDate |
| 345 | case "RubyDate": |
| 346 | timeFormat = time.RubyDate |
| 347 | case "RFC822": |
| 348 | timeFormat = time.RFC822 |
| 349 | case "RFC822Z": |
| 350 | timeFormat = time.RFC822Z |
| 351 | case "RFC850": |
| 352 | timeFormat = time.RFC850 |
| 353 | case "RFC1123": |
| 354 | timeFormat = time.RFC1123 |
| 355 | case "RFC1123Z": |
| 356 | timeFormat = time.RFC1123Z |
| 357 | case "RFC3339": |
| 358 | timeFormat = time.RFC3339 |
| 359 | case "RFC3339Nano": |
| 360 | timeFormat = time.RFC3339Nano |
| 361 | case "Kitchen": |
| 362 | timeFormat = time.Kitchen |
| 363 | case "Stamp": |
| 364 | timeFormat = time.Stamp |
| 365 | case "StampMilli": |
| 366 | timeFormat = time.StampMilli |
| 367 | case "StampMicro": |
| 368 | timeFormat = time.StampMicro |
| 369 | case "StampNano": |
| 370 | timeFormat = time.StampNano |
| 371 | case "DateTime": |
| 372 | timeFormat = time.DateTime |
| 373 | case "DateOnly": |
| 374 | timeFormat = time.DateOnly |
| 375 | case "TimeOnly": |
| 376 | timeFormat = time.TimeOnly |
| 377 | case "MacFriendlyTime", "macfriendlytime", "mac": |
| 378 | timeFormat = "2006-01-02 0304PM" // not actually a Go constant -- but useful as macOS filenames can't have colons |
| 379 | case "YYYYMMDD": |
| 380 | timeFormat = "20060102" |
| 381 | } |
| 382 | return timeFormat |
| 383 | } |
| 384 | |
| 385 | // AppyTimeGlobs converts "myfile-{DateOnly}.txt" to "myfile-2006-01-02.txt" |
| 386 | func AppyTimeGlobs(s string, t time.Time) string { |
no outgoing calls
no test coverage detected
searching dependent graphs…