Skip to content

Commit 63c25a9

Browse files
committed
Adding timezone formatting option
Fixes #315.
1 parent 0d2eb10 commit 63c25a9

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

env/types.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ var pvarNames = []varName{
117117
"time",
118118
`format used to display time/date column values (default "RFC3339Nano")`,
119119
},
120+
{
121+
"timezone",
122+
`the timezone to display dates in (default '')`,
123+
},
120124
{
121125
"title",
122126
"set the table title for subsequently printed tables",
@@ -294,6 +298,7 @@ func init() {
294298
"recordsep_zero": "off",
295299
"tableattr": "",
296300
"time": "RFC3339Nano",
301+
"timezone": "",
297302
"title": "",
298303
"tuples_only": "off",
299304
"unicode_border_linestyle": "single",
@@ -476,7 +481,7 @@ func Ptoggle(name, extra string) (string, error) {
476481
pvars[name] = "aligned"
477482
}
478483
case "linestyle":
479-
case "csv_fieldsep", "fieldsep", "null", "recordsep", "time", "locale":
484+
case "csv_fieldsep", "fieldsep", "null", "recordsep", "time", "timezone", "locale":
480485
case "tableattr", "title":
481486
pvars[name] = ""
482487
case "unicode_border_linestyle", "unicode_column_linestyle", "unicode_header_linestyle":
@@ -526,6 +531,11 @@ func Pset(name, value string) (string, error) {
526531
pvars[name] = value
527532
case "csv_fieldsep", "fieldsep", "null", "recordsep", "tableattr", "time", "title", "locale":
528533
pvars[name] = value
534+
case "timezone":
535+
if _, err := time.LoadLocation(value); err != nil {
536+
return "", text.ErrInvalidTimezoneLocation
537+
}
538+
pvars[name] = value
529539
case "unicode_border_linestyle", "unicode_column_linestyle", "unicode_header_linestyle":
530540
if !borderRE.MatchString(value) {
531541
return "", text.ErrInvalidFormatBorderLineStyle

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ require (
5858
github.com/uber/athenadriver v1.1.15
5959
github.com/vertica/vertica-sql-go v1.3.3
6060
github.com/xo/dburl v0.22.0
61-
github.com/xo/tblfmt v0.13.0
61+
github.com/xo/tblfmt v0.13.1
6262
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e
6363
github.com/ydb-platform/ydb-go-sdk/v3 v3.61.2
6464
github.com/yookoala/realpath v1.0.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,8 @@ github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQ
10391039
github.com/xo/dburl v0.22.0 h1:sO5WLm2ywMzyiLxEcLBlw5AyKvdR5hirq9U7s3fCoeM=
10401040
github.com/xo/dburl v0.22.0/go.mod h1:B7/G9FGungw6ighV8xJNwWYQPMfn3gsi2sn5SE8Bzco=
10411041
github.com/xo/tblfmt v0.0.0-20190609041254-28c54ec42ce8/go.mod h1:3U5kKQdIhwACye7ml3acccHmjGExY9WmUGU7rnDWgv0=
1042-
github.com/xo/tblfmt v0.13.0 h1:mh0ilx9rKZNoMqGwvyMpQv3MED+X6te6ZqB+BzSypck=
1043-
github.com/xo/tblfmt v0.13.0/go.mod h1:BLPC+dRy68cgSK/mPgQRfFQ/xLg231Fyic178ybjB34=
1042+
github.com/xo/tblfmt v0.13.1 h1:lhQAH5OSPhKCEvmh4suPe52woLuF2npX2TLB91CiPZ4=
1043+
github.com/xo/tblfmt v0.13.1/go.mod h1:BLPC+dRy68cgSK/mPgQRfFQ/xLg231Fyic178ybjB34=
10441044
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
10451045
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
10461046
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2 h1:zzrxE1FKn5ryBNl9eKOeqQ58Y/Qpo3Q9QNxKHX5uzzQ=

text/errors.go

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ var (
5555
ErrInvalidFormatLineStyle = errors.New(`\pset: allowed line styles are ascii, old-ascii, unicode`)
5656
// ErrInvalidFormatBorderLineStyle is the invalid format border line style error.
5757
ErrInvalidFormatBorderLineStyle = errors.New(`\pset: allowed Unicode border line styles are single, double`)
58+
// ErrInvalidTimezoneLocation is the invalid timezone location error.
59+
ErrInvalidTimezoneLocation = errors.New(`\pset: invalid timezone location`)
5860
// ErrInvalidQuotedString is the invalid quoted string error.
5961
ErrInvalidQuotedString = errors.New(`invalid quoted string`)
6062
// ErrInvalidFormatOption is the invalid format option error.

0 commit comments

Comments
 (0)