summaryrefslogtreecommitdiff
path: root/src/pkg/time
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/time')
-rw-r--r--src/pkg/time/sleep.go6
-rw-r--r--src/pkg/time/tick.go30
-rw-r--r--src/pkg/time/tick_test.go26
-rw-r--r--src/pkg/time/time.go272
-rw-r--r--src/pkg/time/time_test.go46
-rw-r--r--src/pkg/time/zoneinfo.go136
6 files changed, 258 insertions, 258 deletions
diff --git a/src/pkg/time/sleep.go b/src/pkg/time/sleep.go
index e94057a16..79ca3b6ca 100644
--- a/src/pkg/time/sleep.go
+++ b/src/pkg/time/sleep.go
@@ -5,10 +5,10 @@
package time
import (
- "os";
- "syscall";
+ "os"
+ "syscall"
)
// Sleep pauses the current goroutine for ns nanoseconds.
// It returns os.EINTR if interrupted.
-func Sleep(ns int64) os.Error { return os.NewSyscallError("sleep", syscall.Sleep(ns)) }
+func Sleep(ns int64) os.Error { return os.NewSyscallError("sleep", syscall.Sleep(ns)) }
diff --git a/src/pkg/time/tick.go b/src/pkg/time/tick.go
index cd247d367..a37e8ea4c 100644
--- a/src/pkg/time/tick.go
+++ b/src/pkg/time/tick.go
@@ -23,19 +23,19 @@ package time
// A Ticker holds a synchronous channel that delivers `ticks' of a clock
// at intervals.
type Ticker struct {
- C <-chan int64; // The channel on which the ticks are delivered.
- ns int64;
- shutdown bool;
+ C <-chan int64 // The channel on which the ticks are delivered.
+ ns int64
+ shutdown bool
}
// Stop turns off a ticker. After Stop, no more ticks will be delivered.
-func (t *Ticker) Stop() { t.shutdown = true }
+func (t *Ticker) Stop() { t.shutdown = true }
func (t *Ticker) ticker(c chan<- int64) {
- now := Nanoseconds();
- when := now;
+ now := Nanoseconds()
+ when := now
for !t.shutdown {
- when += t.ns; // next alarm
+ when += t.ns // next alarm
// if c <- now took too long, skip ahead
if when < now {
@@ -47,12 +47,12 @@ func (t *Ticker) ticker(c chan<- int64) {
when += t.ns
}
- Sleep(when - now);
- now = Nanoseconds();
+ Sleep(when - now)
+ now = Nanoseconds()
if t.shutdown {
return
}
- c <- now;
+ c <- now
}
}
@@ -62,7 +62,7 @@ func Tick(ns int64) <-chan int64 {
if ns <= 0 {
return nil
}
- return NewTicker(ns).C;
+ return NewTicker(ns).C
}
// Ticker returns a new Ticker containing a synchronous channel that will
@@ -72,8 +72,8 @@ func NewTicker(ns int64) *Ticker {
if ns <= 0 {
return nil
}
- c := make(chan int64);
- t := &Ticker{c, ns, false};
- go t.ticker(c);
- return t;
+ c := make(chan int64)
+ t := &Ticker{c, ns, false}
+ go t.ticker(c)
+ return t
}
diff --git a/src/pkg/time/tick_test.go b/src/pkg/time/tick_test.go
index 4d1f717ed..e15793aea 100644
--- a/src/pkg/time/tick_test.go
+++ b/src/pkg/time/tick_test.go
@@ -5,31 +5,31 @@
package time_test
import (
- "testing";
- . "time";
+ "testing"
+ . "time"
)
func TestTicker(t *testing.T) {
const (
- Delta = 100 * 1e6;
- Count = 10;
+ Delta = 100 * 1e6
+ Count = 10
)
- ticker := NewTicker(Delta);
- t0 := Nanoseconds();
+ ticker := NewTicker(Delta)
+ t0 := Nanoseconds()
for i := 0; i < Count; i++ {
<-ticker.C
}
- ticker.Stop();
- t1 := Nanoseconds();
- ns := t1 - t0;
- target := int64(Delta * Count);
- slop := target * 2 / 10;
+ ticker.Stop()
+ t1 := Nanoseconds()
+ ns := t1 - t0
+ target := int64(Delta * Count)
+ slop := target * 2 / 10
if ns < target-slop || ns > target+slop {
t.Fatalf("%d ticks of %g ns took %g ns, expected %g", Count, float64(Delta), float64(ns), float64(target))
}
// Now test that the ticker stopped
- Sleep(2 * Delta);
- _, received := <-ticker.C;
+ Sleep(2 * Delta)
+ _, received := <-ticker.C
if received {
t.Fatalf("Ticker did not shut down")
}
diff --git a/src/pkg/time/time.go b/src/pkg/time/time.go
index 1418d521e..e41ca2dc6 100644
--- a/src/pkg/time/time.go
+++ b/src/pkg/time/time.go
@@ -7,48 +7,48 @@
package time
import (
- "os";
+ "os"
)
// Seconds reports the number of seconds since the Unix epoch,
// January 1, 1970 00:00:00 UTC.
func Seconds() int64 {
- sec, _, err := os.Time();
+ sec, _, err := os.Time()
if err != nil {
panic("time: os.Time: ", err.String())
}
- return sec;
+ return sec
}
// Nanoseconds reports the number of nanoseconds since the Unix epoch,
// January 1, 1970 00:00:00 UTC.
func Nanoseconds() int64 {
- sec, nsec, err := os.Time();
+ sec, nsec, err := os.Time()
if err != nil {
panic("time: os.Time: ", err.String())
}
- return sec*1e9 + nsec;
+ return sec*1e9 + nsec
}
// Days of the week.
const (
- Sunday = iota;
- Monday;
- Tuesday;
- Wednesday;
- Thursday;
- Friday;
- Saturday;
+ Sunday = iota
+ Monday
+ Tuesday
+ Wednesday
+ Thursday
+ Friday
+ Saturday
)
// Time is the struct representing a parsed time value.
type Time struct {
- Year int64; // 2008 is 2008
- Month, Day int; // Sep-17 is 9, 17
- Hour, Minute, Second int; // 10:43:12 is 10, 43, 12
- Weekday int; // Sunday, Monday, ...
- ZoneOffset int; // seconds east of UTC
- Zone string;
+ Year int64 // 2008 is 2008
+ Month, Day int // Sep-17 is 9, 17
+ Hour, Minute, Second int // 10:43:12 is 10, 43, 12
+ Weekday int // Sunday, Monday, ...
+ ZoneOffset int // seconds east of UTC
+ Zone string
}
var nonleapyear = []int{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
@@ -58,37 +58,37 @@ func months(year int64) []int {
if year%4 == 0 && (year%100 != 0 || year%400 == 0) {
return leapyear
}
- return nonleapyear;
+ return nonleapyear
}
const (
- secondsPerDay = 24 * 60 * 60;
- daysPer400Years = 365*400 + 97;
- daysPer100Years = 365*100 + 24;
- daysPer4Years = 365*4 + 1;
- days1970To2001 = 31*365 + 8;
+ secondsPerDay = 24 * 60 * 60
+ daysPer400Years = 365*400 + 97
+ daysPer100Years = 365*100 + 24
+ daysPer4Years = 365*4 + 1
+ days1970To2001 = 31*365 + 8
)
// SecondsToUTC converts sec, in number of seconds since the Unix epoch,
// into a parsed Time value in the UTC time zone.
func SecondsToUTC(sec int64) *Time {
- t := new(Time);
+ t := new(Time)
// Split into time and day.
- day := sec / secondsPerDay;
- sec -= day * secondsPerDay;
+ day := sec / secondsPerDay
+ sec -= day * secondsPerDay
if sec < 0 {
- day--;
- sec += secondsPerDay;
+ day--
+ sec += secondsPerDay
}
// Time
- t.Hour = int(sec / 3600);
- t.Minute = int((sec / 60) % 60);
- t.Second = int(sec % 60);
+ t.Hour = int(sec / 3600)
+ t.Minute = int((sec / 60) % 60)
+ t.Second = int(sec % 60)
// Day 0 = January 1, 1970 was a Thursday
- t.Weekday = int((day + Thursday) % 7);
+ t.Weekday = int((day + Thursday) % 7)
if t.Weekday < 0 {
t.Weekday += 7
}
@@ -96,78 +96,78 @@ func SecondsToUTC(sec int64) *Time {
// Change day from 0 = 1970 to 0 = 2001,
// to make leap year calculations easier
// (2001 begins 4-, 100-, and 400-year cycles ending in a leap year.)
- day -= days1970To2001;
+ day -= days1970To2001
- year := int64(2001);
+ year := int64(2001)
if day < 0 {
// Go back enough 400 year cycles to make day positive.
- n := -day/daysPer400Years + 1;
- year -= 400 * n;
- day += daysPer400Years * n;
+ n := -day/daysPer400Years + 1
+ year -= 400 * n
+ day += daysPer400Years * n
}
// Cut off 400 year cycles.
- n := day / daysPer400Years;
- year += 400 * n;
- day -= daysPer400Years * n;
+ n := day / daysPer400Years
+ year += 400 * n
+ day -= daysPer400Years * n
// Cut off 100-year cycles
- n = day / daysPer100Years;
- if n > 3 { // happens on last day of 400th year
+ n = day / daysPer100Years
+ if n > 3 { // happens on last day of 400th year
n = 3
}
- year += 100 * n;
- day -= daysPer100Years * n;
+ year += 100 * n
+ day -= daysPer100Years * n
// Cut off 4-year cycles
- n = day / daysPer4Years;
- if n > 24 { // happens on last day of 100th year
+ n = day / daysPer4Years
+ if n > 24 { // happens on last day of 100th year
n = 24
}
- year += 4 * n;
- day -= daysPer4Years * n;
+ year += 4 * n
+ day -= daysPer4Years * n
// Cut off non-leap years.
- n = day / 365;
- if n > 3 { // happens on last day of 4th year
+ n = day / 365
+ if n > 3 { // happens on last day of 4th year
n = 3
}
- year += n;
- day -= 365 * n;
+ year += n
+ day -= 365 * n
- t.Year = year;
+ t.Year = year
// If someone ever needs yearday,
// tyearday = day (+1?)
- months := months(year);
- var m int;
- yday := int(day);
+ months := months(year)
+ var m int
+ yday := int(day)
for m = 0; m < 12 && yday >= months[m]; m++ {
yday -= months[m]
}
- t.Month = m + 1;
- t.Day = yday + 1;
- t.Zone = "UTC";
+ t.Month = m + 1
+ t.Day = yday + 1
+ t.Zone = "UTC"
- return t;
+ return t
}
// UTC returns the current time as a parsed Time value in the UTC time zone.
-func UTC() *Time { return SecondsToUTC(Seconds()) }
+func UTC() *Time { return SecondsToUTC(Seconds()) }
// SecondsToLocalTime converts sec, in number of seconds since the Unix epoch,
// into a parsed Time value in the local time zone.
func SecondsToLocalTime(sec int64) *Time {
- z, offset := lookupTimezone(sec);
- t := SecondsToUTC(sec + int64(offset));
- t.Zone = z;
- t.ZoneOffset = offset;
- return t;
+ z, offset := lookupTimezone(sec)
+ t := SecondsToUTC(sec + int64(offset))
+ t.Zone = z
+ t.ZoneOffset = offset
+ return t
}
// LocalTime returns the current time as a parsed Time value in the local time zone.
-func LocalTime() *Time { return SecondsToLocalTime(Seconds()) }
+func LocalTime() *Time { return SecondsToLocalTime(Seconds()) }
// Seconds returns the number of seconds since January 1, 1970 represented by the
// parsed Time value.
@@ -176,56 +176,56 @@ func (t *Time) Seconds() int64 {
// Using 2001 instead of 1970 makes the leap-year
// handling easier (see SecondsToUTC), because
// it is at the beginning of the 4-, 100-, and 400-year cycles.
- day := int64(0);
+ day := int64(0)
// Rewrite year to be >= 2001.
- year := t.Year;
+ year := t.Year
if year < 2001 {
- n := (2001-year)/400 + 1;
- year += 400 * n;
- day -= daysPer400Years * n;
+ n := (2001-year)/400 + 1
+ year += 400 * n
+ day -= daysPer400Years * n
}
// Add in days from 400-year cycles.
- n := (year - 2001) / 400;
- year -= 400 * n;
- day += daysPer400Years * n;
+ n := (year - 2001) / 400
+ year -= 400 * n
+ day += daysPer400Years * n
// Add in 100-year cycles.
- n = (year - 2001) / 100;
- year -= 100 * n;
- day += daysPer100Years * n;
+ n = (year - 2001) / 100
+ year -= 100 * n
+ day += daysPer100Years * n
// Add in 4-year cycles.
- n = (year - 2001) / 4;
- year -= 4 * n;
- day += daysPer4Years * n;
+ n = (year - 2001) / 4
+ year -= 4 * n
+ day += daysPer4Years * n
// Add in non-leap years.
- n = year - 2001;
- day += 365 * n;
+ n = year - 2001
+ day += 365 * n
// Add in days this year.
- months := months(t.Year);
+ months := months(t.Year)
for m := 0; m < t.Month-1; m++ {
day += int64(months[m])
}
- day += int64(t.Day - 1);
+ day += int64(t.Day - 1)
// Convert days to seconds since January 1, 2001.
- sec := day * secondsPerDay;
+ sec := day * secondsPerDay
// Add in time elapsed today.
- sec += int64(t.Hour) * 3600;
- sec += int64(t.Minute) * 60;
- sec += int64(t.Second);
+ sec += int64(t.Hour) * 3600
+ sec += int64(t.Minute) * 60
+ sec += int64(t.Second)
// Convert from seconds since 2001 to seconds since 1970.
- sec += days1970To2001 * secondsPerDay;
+ sec += days1970To2001 * secondsPerDay
// Account for local time zone.
- sec -= int64(t.ZoneOffset);
- return sec;
+ sec -= int64(t.ZoneOffset)
+ return sec
}
var longDayNames = []string{
@@ -275,86 +275,86 @@ func decimal(dst []byte, n int) {
n = 0
}
for i := len(dst) - 1; i >= 0; i-- {
- dst[i] = byte(n%10 + '0');
- n /= 10;
+ dst[i] = byte(n%10 + '0')
+ n /= 10
}
}
func addString(buf []byte, bp int, s string) int {
- n := len(s);
- copy(buf[bp:bp+n], s);
- return bp + n;
+ n := len(s)
+ copy(buf[bp:bp+n], s)
+ return bp + n
}
// Just enough of strftime to implement the date formats below.
// Not exported.
func format(t *Time, fmt string) string {
- buf := make([]byte, 128);
- bp := 0;
+ buf := make([]byte, 128)
+ bp := 0
for i := 0; i < len(fmt); i++ {
if fmt[i] == '%' {
- i++;
+ i++
switch fmt[i] {
- case 'A': // %A full weekday name
+ case 'A': // %A full weekday name
bp = addString(buf, bp, longDayNames[t.Weekday])
- case 'a': // %a abbreviated weekday name
+ case 'a': // %a abbreviated weekday name
bp = addString(buf, bp, shortDayNames[t.Weekday])
- case 'b': // %b abbreviated month name
+ case 'b': // %b abbreviated month name
bp = addString(buf, bp, shortMonthNames[t.Month])
- case 'd': // %d day of month (01-31)
- decimal(buf[bp:bp+2], t.Day);
- bp += 2;
- case 'e': // %e day of month ( 1-31)
+ case 'd': // %d day of month (01-31)
+ decimal(buf[bp:bp+2], t.Day)
+ bp += 2
+ case 'e': // %e day of month ( 1-31)
if t.Day >= 10 {
decimal(buf[bp:bp+2], t.Day)
} else {
- buf[bp] = ' ';
- buf[bp+1] = byte(t.Day + '0');
+ buf[bp] = ' '
+ buf[bp+1] = byte(t.Day + '0')
}
- bp += 2;
- case 'H': // %H hour 00-23
- decimal(buf[bp:bp+2], t.Hour);
- bp += 2;
- case 'M': // %M minute 00-59
- decimal(buf[bp:bp+2], t.Minute);
- bp += 2;
- case 'S': // %S second 00-59
- decimal(buf[bp:bp+2], t.Second);
- bp += 2;
- case 'Y': // %Y year 2008
- decimal(buf[bp:bp+4], int(t.Year));
- bp += 4;
- case 'y': // %y year 08
- decimal(buf[bp:bp+2], int(t.Year%100));
- bp += 2;
+ bp += 2
+ case 'H': // %H hour 00-23
+ decimal(buf[bp:bp+2], t.Hour)
+ bp += 2
+ case 'M': // %M minute 00-59
+ decimal(buf[bp:bp+2], t.Minute)
+ bp += 2
+ case 'S': // %S second 00-59
+ decimal(buf[bp:bp+2], t.Second)
+ bp += 2
+ case 'Y': // %Y year 2008
+ decimal(buf[bp:bp+4], int(t.Year))
+ bp += 4
+ case 'y': // %y year 08
+ decimal(buf[bp:bp+2], int(t.Year%100))
+ bp += 2
case 'Z':
bp = addString(buf, bp, t.Zone)
default:
- buf[bp] = '%';
- buf[bp+1] = fmt[i];
- bp += 2;
+ buf[bp] = '%'
+ buf[bp+1] = fmt[i]
+ bp += 2
}
} else {
- buf[bp] = fmt[i];
- bp++;
+ buf[bp] = fmt[i]
+ bp++
}
}
- return string(buf[0:bp]);
+ return string(buf[0:bp])
}
// Asctime formats the parsed time value in the style of
// ANSI C asctime: Sun Nov 6 08:49:37 1994
-func (t *Time) Asctime() string { return format(t, "%a %b %e %H:%M:%S %Y") }
+func (t *Time) Asctime() string { return format(t, "%a %b %e %H:%M:%S %Y") }
// RFC850 formats the parsed time value in the style of
// RFC 850: Sunday, 06-Nov-94 08:49:37 UTC
-func (t *Time) RFC850() string { return format(t, "%A, %d-%b-%y %H:%M:%S %Z") }
+func (t *Time) RFC850() string { return format(t, "%A, %d-%b-%y %H:%M:%S %Z") }
// RFC1123 formats the parsed time value in the style of
// RFC 1123: Sun, 06 Nov 1994 08:49:37 UTC
-func (t *Time) RFC1123() string { return format(t, "%a, %d %b %Y %H:%M:%S %Z") }
+func (t *Time) RFC1123() string { return format(t, "%a, %d %b %Y %H:%M:%S %Z") }
// String formats the parsed time value in the style of
// date(1) - Sun Nov 6 08:49:37 UTC 1994
-func (t *Time) String() string { return format(t, "%a %b %e %H:%M:%S %Z %Y") }
+func (t *Time) String() string { return format(t, "%a %b %e %H:%M:%S %Z %Y") }
diff --git a/src/pkg/time/time_test.go b/src/pkg/time/time_test.go
index 88b16ee26..23040d8ed 100644
--- a/src/pkg/time/time_test.go
+++ b/src/pkg/time/time_test.go
@@ -5,10 +5,10 @@
package time_test
import (
- "os";
- "testing";
- "testing/quick";
- . "time";
+ "os"
+ "testing"
+ "testing/quick"
+ . "time"
)
func init() {
@@ -19,8 +19,8 @@ func init() {
}
type TimeTest struct {
- seconds int64;
- golden Time;
+ seconds int64
+ golden Time
}
var utctests = []TimeTest{
@@ -55,42 +55,42 @@ func same(t, u *Time) bool {
func TestSecondsToUTC(t *testing.T) {
for i := 0; i < len(utctests); i++ {
- sec := utctests[i].seconds;
- golden := &utctests[i].golden;
- tm := SecondsToUTC(sec);
- newsec := tm.Seconds();
+ sec := utctests[i].seconds
+ golden := &utctests[i].golden
+ tm := SecondsToUTC(sec)
+ newsec := tm.Seconds()
if newsec != sec {
t.Errorf("SecondsToUTC(%d).Seconds() = %d", sec, newsec)
}
if !same(tm, golden) {
- t.Errorf("SecondsToUTC(%d):", sec);
- t.Errorf(" want=%+v", *golden);
- t.Errorf(" have=%+v", *tm);
+ t.Errorf("SecondsToUTC(%d):", sec)
+ t.Errorf(" want=%+v", *golden)
+ t.Errorf(" have=%+v", *tm)
}
}
}
func TestSecondsToLocalTime(t *testing.T) {
for i := 0; i < len(localtests); i++ {
- sec := localtests[i].seconds;
- golden := &localtests[i].golden;
- tm := SecondsToLocalTime(sec);
- newsec := tm.Seconds();
+ sec := localtests[i].seconds
+ golden := &localtests[i].golden
+ tm := SecondsToLocalTime(sec)
+ newsec := tm.Seconds()
if newsec != sec {
t.Errorf("SecondsToLocalTime(%d).Seconds() = %d", sec, newsec)
}
if !same(tm, golden) {
- t.Errorf("SecondsToLocalTime(%d):", sec);
- t.Errorf(" want=%+v", *golden);
- t.Errorf(" have=%+v", *tm);
+ t.Errorf("SecondsToLocalTime(%d):", sec)
+ t.Errorf(" want=%+v", *golden)
+ t.Errorf(" have=%+v", *tm)
}
}
}
func TestSecondsToUTCAndBack(t *testing.T) {
- f := func(sec int64) bool { return SecondsToUTC(sec).Seconds() == sec };
- f32 := func(sec int32) bool { return f(int64(sec)) };
- cfg := &quick.Config{MaxCount: 10000};
+ f := func(sec int64) bool { return SecondsToUTC(sec).Seconds() == sec }
+ f32 := func(sec int32) bool { return f(int64(sec)) }
+ cfg := &quick.Config{MaxCount: 10000}
// Try a reasonable date first, then the huge ones.
if err := quick.Check(f32, cfg); err != nil {
diff --git a/src/pkg/time/zoneinfo.go b/src/pkg/time/zoneinfo.go
index 8d8048aa0..98d816b10 100644
--- a/src/pkg/time/zoneinfo.go
+++ b/src/pkg/time/zoneinfo.go
@@ -10,50 +10,50 @@
package time
import (
- "io/ioutil";
- "once";
- "os";
+ "io/ioutil"
+ "once"
+ "os"
)
const (
- headerSize = 4 + 16 + 4*7;
- zoneDir = "/usr/share/zoneinfo/";
+ headerSize = 4 + 16 + 4*7
+ zoneDir = "/usr/share/zoneinfo/"
)
// Simple I/O interface to binary blob of data.
type data struct {
- p []byte;
- error bool;
+ p []byte
+ error bool
}
func (d *data) read(n int) []byte {
if len(d.p) < n {
- d.p = nil;
- d.error = true;
- return nil;
+ d.p = nil
+ d.error = true
+ return nil
}
- p := d.p[0:n];
- d.p = d.p[n:];
- return p;
+ p := d.p[0:n]
+ d.p = d.p[n:]
+ return p
}
func (d *data) big4() (n uint32, ok bool) {
- p := d.read(4);
+ p := d.read(4)
if len(p) < 4 {
- d.error = true;
- return 0, false;
+ d.error = true
+ return 0, false
}
- return uint32(p[0])<<24 | uint32(p[1])<<16 | uint32(p[2])<<8 | uint32(p[3]), true;
+ return uint32(p[0])<<24 | uint32(p[1])<<16 | uint32(p[2])<<8 | uint32(p[3]), true
}
func (d *data) byte() (n byte, ok bool) {
- p := d.read(1);
+ p := d.read(1)
if len(p) < 1 {
- d.error = true;
- return 0, false;
+ d.error = true
+ return 0, false
}
- return p[0], true;
+ return p[0], true
}
@@ -64,24 +64,24 @@ func byteString(p []byte) string {
return string(p[0:i])
}
}
- return string(p);
+ return string(p)
}
// Parsed representation
type zone struct {
- utcoff int;
- isdst bool;
- name string;
+ utcoff int
+ isdst bool
+ name string
}
type zonetime struct {
- time int32; // transition time, in seconds since 1970 GMT
- zone *zone; // the zone that goes into effect at that time
- isstd, isutc bool; // ignored - no idea what these mean
+ time int32 // transition time, in seconds since 1970 GMT
+ zone *zone // the zone that goes into effect at that time
+ isstd, isutc bool // ignored - no idea what these mean
}
func parseinfo(bytes []byte) (zt []zonetime, ok bool) {
- d := data{bytes, false};
+ d := data{bytes, false}
// 4-byte magic "TZif"
if magic := d.read(4); string(magic) != "TZif" {
@@ -89,7 +89,7 @@ func parseinfo(bytes []byte) (zt []zonetime, ok bool) {
}
// 1-byte version, then 15 bytes of padding
- var p []byte;
+ var p []byte
if p = d.read(16); len(p) != 16 || p[0] != 0 && p[0] != '2' {
return nil, false
}
@@ -102,46 +102,46 @@ func parseinfo(bytes []byte) (zt []zonetime, ok bool) {
// number of local time zones
// number of characters of time zone abbrev strings
const (
- NUTCLocal = iota;
- NStdWall;
- NLeap;
- NTime;
- NZone;
- NChar;
+ NUTCLocal = iota
+ NStdWall
+ NLeap
+ NTime
+ NZone
+ NChar
)
- var n [6]int;
+ var n [6]int
for i := 0; i < 6; i++ {
- nn, ok := d.big4();
+ nn, ok := d.big4()
if !ok {
return nil, false
}
- n[i] = int(nn);
+ n[i] = int(nn)
}
// Transition times.
- txtimes := data{d.read(n[NTime] * 4), false};
+ txtimes := data{d.read(n[NTime] * 4), false}
// Time zone indices for transition times.
- txzones := d.read(n[NTime]);
+ txzones := d.read(n[NTime])
// Zone info structures
- zonedata := data{d.read(n[NZone] * 6), false};
+ zonedata := data{d.read(n[NZone] * 6), false}
// Time zone abbreviations.
- abbrev := d.read(n[NChar]);
+ abbrev := d.read(n[NChar])
// Leap-second time pairs
- d.read(n[NLeap] * 8);
+ d.read(n[NLeap] * 8)
// Whether tx times associated with local time types
// are specified as standard time or wall time.
- isstd := d.read(n[NStdWall]);
+ isstd := d.read(n[NStdWall])
// Whether tx times associated with local time types
// are specified as UTC or local time.
- isutc := d.read(n[NUTCLocal]);
+ isutc := d.read(n[NUTCLocal])
- if d.error { // ran out of data
+ if d.error { // ran out of data
return nil, false
}
@@ -152,38 +152,38 @@ func parseinfo(bytes []byte) (zt []zonetime, ok bool) {
// Now we can build up a useful data structure.
// First the zone information.
// utcoff[4] isdst[1] nameindex[1]
- z := make([]zone, n[NZone]);
+ z := make([]zone, n[NZone])
for i := 0; i < len(z); i++ {
- var ok bool;
- var n uint32;
+ var ok bool
+ var n uint32
if n, ok = zonedata.big4(); !ok {
return nil, false
}
- z[i].utcoff = int(n);
- var b byte;
+ z[i].utcoff = int(n)
+ var b byte
if b, ok = zonedata.byte(); !ok {
return nil, false
}
- z[i].isdst = b != 0;
+ z[i].isdst = b != 0
if b, ok = zonedata.byte(); !ok || int(b) >= len(abbrev) {
return nil, false
}
- z[i].name = byteString(abbrev[b:]);
+ z[i].name = byteString(abbrev[b:])
}
// Now the transition time info.
- zt = make([]zonetime, n[NTime]);
+ zt = make([]zonetime, n[NTime])
for i := 0; i < len(zt); i++ {
- var ok bool;
- var n uint32;
+ var ok bool
+ var n uint32
if n, ok = txtimes.big4(); !ok {
return nil, false
}
- zt[i].time = int32(n);
+ zt[i].time = int32(n)
if int(txzones[i]) >= len(z) {
return nil, false
}
- zt[i].zone = &z[txzones[i]];
+ zt[i].zone = &z[txzones[i]]
if i < len(isstd) {
zt[i].isstd = isstd[i] != 0
}
@@ -191,15 +191,15 @@ func parseinfo(bytes []byte) (zt []zonetime, ok bool) {
zt[i].isutc = isutc[i] != 0
}
}
- return zt, true;
+ return zt, true
}
func readinfofile(name string) ([]zonetime, bool) {
- buf, err := ioutil.ReadFile(name);
+ buf, err := ioutil.ReadFile(name)
if err != nil {
return nil, false
}
- return parseinfo(buf);
+ return parseinfo(buf)
}
var zones []zonetime
@@ -210,7 +210,7 @@ func setupZone() {
// $TZ="" means use UTC.
// $TZ="foo" means use /usr/share/zoneinfo/foo.
- tz, err := os.Getenverror("TZ");
+ tz, err := os.Getenverror("TZ")
switch {
case err == os.ENOENV:
zones, _ = readinfofile("/etc/localtime")
@@ -222,21 +222,21 @@ func setupZone() {
}
func lookupTimezone(sec int64) (zone string, offset int) {
- once.Do(setupZone);
+ once.Do(setupZone)
if len(zones) == 0 {
return "UTC", 0
}
// Binary search for entry with largest time <= sec
- tz := zones;
+ tz := zones
for len(tz) > 1 {
- m := len(tz) / 2;
+ m := len(tz) / 2
if sec < int64(tz[m].time) {
tz = tz[0:m]
} else {
tz = tz[m:]
}
}
- z := tz[0].zone;
- return z.name, z.utcoff;
+ z := tz[0].zone
+ return z.name, z.utcoff
}