Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Kirill Smelkov
go
Commits
65ad3ce1
Commit
65ad3ce1
authored
16 years ago
by
Russ Cox
Browse files
Options
Download
Email Patches
Plain Diff
make time fields public
R=r DELTA=49 (0 added, 0 deleted, 49 changed) OCL=23480 CL=23487
parent
a01bdb4a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
49 deletions
+49
-49
src/lib/Makefile
src/lib/Makefile
+1
-1
src/lib/time/time.go
src/lib/time/time.go
+39
-39
src/lib/time/time_test.go
src/lib/time/time_test.go
+9
-9
No files found.
src/lib/Makefile
View file @
65ad3ce1
...
...
@@ -109,6 +109,6 @@ regexp.dirinstall: os.dirinstall
reflect.dirinstall
:
strconv.dirinstall sync.dirinstall
strconv.dirinstall
:
math.dirinstall os.dirinstall utf8.install
tabwriter.dirinstall
:
os.dirinstall io.dirinstall container/array.dirinstall
time.dirinstall
:
once.install os.dirinstall
time.dirinstall
:
once.install os.dirinstall
io.dirinstall
sync.dirinstall
:
This diff is collapsed.
Click to expand it.
src/lib/time/time.go
View file @
65ad3ce1
...
...
@@ -38,12 +38,12 @@ const (
)
type
Time
struct
{
y
ear
int64
;
// 2008 is 2008
m
onth
,
d
ay
int
;
// Sep-17 is 9, 17
h
our
,
m
inute
,
s
econd
int
;
// 10:43:12 is 10, 43, 12
w
eekday
int
;
// Sunday = 0, Monday = 1, ...
z
one
o
ffset
int
;
// seconds west of UTC
z
one
string
;
Y
ear
int64
;
// 2008 is 2008
M
onth
,
D
ay
int
;
// Sep-17 is 9, 17
H
our
,
M
inute
,
S
econd
int
;
// 10:43:12 is 10, 43, 12
W
eekday
int
;
// Sunday = 0, Monday = 1, ...
Z
one
O
ffset
int
;
// seconds west of UTC
Z
one
string
;
}
var
nonleapyear
=
[]
int
{
...
...
@@ -82,14 +82,14 @@ func SecondsToUTC(sec int64) *Time {
}
// Time
t
.
h
our
=
int
(
sec
/
3600
);
t
.
m
inute
=
int
((
sec
/
60
)
%
60
);
t
.
s
econd
=
int
(
sec
%
60
);
t
.
H
our
=
int
(
sec
/
3600
);
t
.
M
inute
=
int
((
sec
/
60
)
%
60
);
t
.
S
econd
=
int
(
sec
%
60
);
// Day 0 = January 1, 1970 was a Thursday
t
.
w
eekday
=
int
((
day
+
Thursday
)
%
7
);
if
t
.
w
eekday
<
0
{
t
.
w
eekday
+=
7
t
.
W
eekday
=
int
((
day
+
Thursday
)
%
7
);
if
t
.
W
eekday
<
0
{
t
.
W
eekday
+=
7
}
// Change day from 0 = 1970 to 0 = 2001,
...
...
@@ -125,7 +125,7 @@ func SecondsToUTC(sec int64) *Time {
year
+=
n
;
day
-=
365
*
n
;
t
.
y
ear
=
year
;
t
.
Y
ear
=
year
;
// If someone ever needs yearday,
// tyearday = day (+1?)
...
...
@@ -136,9 +136,9 @@ func SecondsToUTC(sec int64) *Time {
for
m
=
0
;
m
<
12
&&
yday
>=
months
[
m
];
m
++
{
yday
-=
months
[
m
]
}
t
.
m
onth
=
m
+
1
;
t
.
d
ay
=
yday
+
1
;
t
.
z
one
=
"GMT"
;
t
.
M
onth
=
m
+
1
;
t
.
D
ay
=
yday
+
1
;
t
.
Z
one
=
"GMT"
;
return
t
;
}
...
...
@@ -154,8 +154,8 @@ func SecondsToLocalTime(sec int64) *Time {
return
SecondsToUTC
(
sec
)
}
t
:=
SecondsToUTC
(
sec
+
int64
(
offset
));
t
.
z
one
=
zone
;
t
.
z
one
o
ffset
=
offset
;
t
.
Z
one
=
zone
;
t
.
Z
one
O
ffset
=
offset
;
return
t
}
...
...
@@ -172,7 +172,7 @@ func (t *Time) Seconds() int64 {
day
:=
int64
(
0
);
// Rewrite year to be >= 2001.
year
:=
t
.
y
ear
;
year
:=
t
.
Y
ear
;
if
year
<
2001
{
n
:=
(
2001
-
year
)
/
400
+
1
;
year
+=
400
*
n
;
...
...
@@ -199,25 +199,25 @@ func (t *Time) Seconds() int64 {
day
+=
365
*
n
;
// Add in days this year.
months
:=
months
(
t
.
y
ear
);
for
m
:=
0
;
m
<
t
.
m
onth
-
1
;
m
++
{
months
:=
months
(
t
.
Y
ear
);
for
m
:=
0
;
m
<
t
.
M
onth
-
1
;
m
++
{
day
+=
int64
(
months
[
m
])
}
day
+=
int64
(
t
.
d
ay
-
1
);
day
+=
int64
(
t
.
D
ay
-
1
);
// Convert days to seconds since January 1, 2001.
sec
:=
day
*
_SecondsPerDay
;
// Add in time elapsed today.
sec
+=
int64
(
t
.
h
our
)
*
3600
;
sec
+=
int64
(
t
.
m
inute
)
*
60
;
sec
+=
int64
(
t
.
s
econd
);
sec
+=
int64
(
t
.
H
our
)
*
3600
;
sec
+=
int64
(
t
.
M
inute
)
*
60
;
sec
+=
int64
(
t
.
S
econd
);
// Convert from seconds since 2001 to seconds since 1970.
sec
+=
_Days1970To2001
*
_SecondsPerDay
;
// Account for local time zone.
sec
-=
int64
(
t
.
z
one
o
ffset
);
sec
-=
int64
(
t
.
Z
one
O
ffset
);
return
sec
}
...
...
@@ -289,39 +289,39 @@ func _Format(t *Time, fmt string) string {
i
++
;
switch
fmt
[
i
]
{
case
'A'
:
// %A full weekday name
bp
=
_AddString
(
buf
,
bp
,
_LongDayNames
[
t
.
w
eekday
]);
bp
=
_AddString
(
buf
,
bp
,
_LongDayNames
[
t
.
W
eekday
]);
case
'a'
:
// %a abbreviated weekday name
bp
=
_AddString
(
buf
,
bp
,
_ShortDayNames
[
t
.
w
eekday
]);
bp
=
_AddString
(
buf
,
bp
,
_ShortDayNames
[
t
.
W
eekday
]);
case
'b'
:
// %b abbreviated month name
bp
=
_AddString
(
buf
,
bp
,
_ShortMonthNames
[
t
.
m
onth
-
1
]);
bp
=
_AddString
(
buf
,
bp
,
_ShortMonthNames
[
t
.
M
onth
-
1
]);
case
'd'
:
// %d day of month (01-31)
_Decimal
(
buf
[
bp
:
bp
+
2
],
t
.
d
ay
);
_Decimal
(
buf
[
bp
:
bp
+
2
],
t
.
D
ay
);
bp
+=
2
;
case
'e'
:
// %e day of month ( 1-31)
if
t
.
d
ay
>=
10
{
_Decimal
(
buf
[
bp
:
bp
+
2
],
t
.
d
ay
)
if
t
.
D
ay
>=
10
{
_Decimal
(
buf
[
bp
:
bp
+
2
],
t
.
D
ay
)
}
else
{
buf
[
bp
]
=
' '
;
buf
[
bp
+
1
]
=
byte
(
t
.
d
ay
+
'0'
)
buf
[
bp
+
1
]
=
byte
(
t
.
D
ay
+
'0'
)
}
bp
+=
2
;
case
'H'
:
// %H hour 00-23
_Decimal
(
buf
[
bp
:
bp
+
2
],
t
.
h
our
);
_Decimal
(
buf
[
bp
:
bp
+
2
],
t
.
H
our
);
bp
+=
2
;
case
'M'
:
// %M minute 00-59
_Decimal
(
buf
[
bp
:
bp
+
2
],
t
.
m
inute
);
_Decimal
(
buf
[
bp
:
bp
+
2
],
t
.
M
inute
);
bp
+=
2
;
case
'S'
:
// %S second 00-59
_Decimal
(
buf
[
bp
:
bp
+
2
],
t
.
s
econd
);
_Decimal
(
buf
[
bp
:
bp
+
2
],
t
.
S
econd
);
bp
+=
2
;
case
'Y'
:
// %Y year 2008
_Decimal
(
buf
[
bp
:
bp
+
4
],
int
(
t
.
y
ear
));
_Decimal
(
buf
[
bp
:
bp
+
4
],
int
(
t
.
Y
ear
));
bp
+=
4
;
case
'y'
:
// %y year 08
_Decimal
(
buf
[
bp
:
bp
+
2
],
int
(
t
.
y
ear
%
100
));
_Decimal
(
buf
[
bp
:
bp
+
2
],
int
(
t
.
Y
ear
%
100
));
bp
+=
2
;
case
'Z'
:
bp
=
_AddString
(
buf
,
bp
,
t
.
z
one
);
bp
=
_AddString
(
buf
,
bp
,
t
.
Z
one
);
default
:
buf
[
bp
]
=
'%'
;
buf
[
bp
+
1
]
=
fmt
[
i
];
...
...
This diff is collapsed.
Click to expand it.
src/lib/time/time_test.go
View file @
65ad3ce1
...
...
@@ -30,15 +30,15 @@ var localtests = []_TimeTest {
}
func
_Same
(
t
,
u
*
Time
)
bool
{
return
t
.
y
ear
==
u
.
y
ear
&&
t
.
m
onth
==
u
.
m
onth
&&
t
.
d
ay
==
u
.
d
ay
&&
t
.
h
our
==
u
.
h
our
&&
t
.
m
inute
==
u
.
m
inute
&&
t
.
s
econd
==
u
.
s
econd
&&
t
.
w
eekday
==
u
.
w
eekday
&&
t
.
z
one
o
ffset
==
u
.
z
one
o
ffset
&&
t
.
z
one
==
u
.
z
one
return
t
.
Y
ear
==
u
.
Y
ear
&&
t
.
M
onth
==
u
.
M
onth
&&
t
.
D
ay
==
u
.
D
ay
&&
t
.
H
our
==
u
.
H
our
&&
t
.
M
inute
==
u
.
M
inute
&&
t
.
S
econd
==
u
.
S
econd
&&
t
.
W
eekday
==
u
.
W
eekday
&&
t
.
Z
one
O
ffset
==
u
.
Z
one
O
ffset
&&
t
.
Z
one
==
u
.
Z
one
}
func
TestSecondsToUTC
(
t
*
testing
.
T
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment