-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f43c66d
commit aaae775
Showing
4 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package noarch | ||
|
||
import "time" | ||
|
||
// TimeT is the representation of "time_t". | ||
type TimeT int32 | ||
|
||
// NullToTimeT converts a NULL to an array of TimeT. | ||
func NullToTimeT(i int32) []TimeT { | ||
return []TimeT{} | ||
} | ||
|
||
// Time returns the current time. | ||
func Time(tloc []TimeT) TimeT { | ||
var t = TimeT(int32(time.Now().Unix())) | ||
|
||
if len(tloc) > 0 { | ||
tloc[0] = t | ||
} | ||
|
||
return t | ||
} | ||
|
||
// IntToTimeT converts an int32 to a TimeT. | ||
func IntToTimeT(t int32) TimeT { | ||
return TimeT(t) | ||
} | ||
|
||
// Ctime converts TimeT to a string. | ||
func Ctime(tloc []TimeT) []byte { | ||
if len(tloc) > 0 { | ||
var t = time.Unix(int64(tloc[0]), 0) | ||
return []byte(t.Format(time.ANSIC) + "\n") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// TimeTToFloat64 converts TimeT to a float64. It is used by the tests. | ||
func TimeTToFloat64(t TimeT) float64 { | ||
return float64(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <stdio.h> | ||
#include <time.h> | ||
|
||
#include "tests.h" | ||
|
||
#define START_TEST(t) \ | ||
diag(#t); \ | ||
test_##t(); | ||
|
||
void test_time() | ||
{ | ||
time_t now; | ||
time_t tloc; | ||
|
||
now = time(NULL); | ||
is_not_eq(now, 0); | ||
|
||
now = time(&tloc); | ||
is_not_eq(now, 0); | ||
is_eq(now, tloc); | ||
} | ||
|
||
void test_ctime() | ||
{ | ||
char* s; | ||
|
||
// 1999-12-31 11:59:58 | ||
time_t now = 946670398; | ||
s = ctime(&now); | ||
is_not_null(s); | ||
|
||
// Hours/minutes will vary based on local time. Ignore them. | ||
s[11] = 'H'; | ||
s[12] = 'H'; | ||
s[14] = 'm'; | ||
s[15] = 'm'; | ||
is_streq(s, "Fri Dec 31 HH:mm:58 1999\n"); | ||
} | ||
|
||
int main() | ||
{ | ||
plan(5); | ||
|
||
START_TEST(time) | ||
START_TEST(ctime) | ||
|
||
done_testing(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters