1
0
Fork 0

Render and accept the minus sign, tweak weights

main
Ambrose Chua 2020-11-10 23:51:07 +08:00
parent 949bbc0bb8
commit 4776226b6e
3 changed files with 30 additions and 14 deletions

View File

@ -5,7 +5,7 @@
html {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-feature-settings: "case", "tnum", "ss03", "cv09", "cv08", "cv10", "cv11";
line-height: 1.5;
line-height: 1.4;
}
@supports (font-variation-settings: normal) {
html {
@ -204,22 +204,25 @@ d-zoneinfo {
d-zonename {
display: inline;
font-size: 0.75em;
font-weight: 600;
}
d-zoneoffset {
display: inline;
white-space: nowrap;
font-size: 0.75em;
opacity: 0.5;
}
@media (max-width: 675px) {
d-zoneoffset {
display: block;
}
}
d-date {
margin-top: 0.25em;
display: block;
margin-top: 0.25em;
font-size: 1.2em;
}
/* Right container */

View File

@ -5,6 +5,7 @@ import (
"fmt"
"regexp"
"strconv"
"strings"
)
// ErrZoneOffsetInvalid is thrown when a zone string is an invalid zone offset
@ -13,7 +14,7 @@ var ErrZoneOffsetInvalid = errors.New("offset zone invalid")
const zoneHour = 60 * 60
const zoneMinute = 60
var zoneOffsetRegexp = regexp.MustCompile(`^[+-][0-9]{2}:[0-9]{2}$`)
var zoneOffsetRegexp = regexp.MustCompile("^[+-\u2212][0-9]{2}:[0-9]{2}$")
// ParseZoneOffset parses a zone string into an offset
func ParseZoneOffset(zone string) (int, error) {
@ -23,15 +24,17 @@ func ParseZoneOffset(zone string) (int, error) {
// Assume that if it satisfies the regex, it satisfies the length and won't
// fail to parse
d := 0
if zone[0] == '+' {
if strings.HasPrefix(zone, "+") {
d = 1
}
if zone[0] == '-' {
if strings.HasPrefix(zone, "-") || strings.HasPrefix(zone, "\u2212") {
d = -1
}
h, _ := strconv.ParseUint(zone[1:1+2], 10, 64)
zone = strings.TrimLeft(zone, "+-\u2212")
parts := strings.Split(zone, ":")
h, _ := strconv.ParseUint(parts[0], 10, 64)
// Allow hour offsets greater that 24
m, _ := strconv.ParseUint(zone[1+3:1+3+2], 10, 64)
m, _ := strconv.ParseUint(parts[1], 10, 64)
if m >= 60 {
return 0, ErrZoneOffsetInvalid
}
@ -44,11 +47,11 @@ func FormatZoneOffset(offset int) string {
neg := offset < 0
s := '+'
if neg {
s = '-'
s = '\u2212'
offset = -offset
}
if offset == 0 {
return "\u00B100:00"
return "\u00b100:00"
}
h := offset / zoneHour
m := (offset % zoneHour) / zoneMinute

View File

@ -26,6 +26,16 @@ func TestParseZoneOffset(t *testing.T) {
}
}
offset, err = ParseZoneOffset("\u221251:59")
if err != nil {
t.Errorf("want error %v, got error %v", nil, err)
} else {
want := -(51*60*60 + 59*60)
if offset != want {
t.Errorf("got %d, want %d", offset, want)
}
}
_, err = ParseZoneOffset("-0030")
if err != ErrZoneOffsetInvalid {
t.Errorf("want error %v, got error %v", ErrZoneOffsetInvalid, err)
@ -77,7 +87,7 @@ func TestFormatZoneOffset(t *testing.T) {
t.Fatalf("got offset %v, want offset %v", got, want)
}
want, got = "-12:15", FormatZoneOffset(-(12*60*60 + 15*60))
want, got = "\u221212:15", FormatZoneOffset(-(12*60*60 + 15*60))
if want != got {
t.Fatalf("got offset %v, want offset %v", got, want)
}