time: clean up

pull/759/head
Alexander Medvednikov 2019-06-28 16:04:14 +02:00
parent b81f615a75
commit 0b7cc5f01a
4 changed files with 44 additions and 90 deletions

View File

@ -68,7 +68,7 @@ pub fn convert_ctime(t tm) Time {
// uni = uni;
}
fn (t Time) format_ss() string {
pub fn (t Time) format_ss() string {
return '${t.year}-${t.month:02d}-${t.day:02d} ${t.hour:02d}:${t.minute:02d}:${t.second:02d}'
}
@ -114,17 +114,17 @@ pub fn (t Time) hhmm12() string {
}
// 21:04:03
fn (t Time) hhmmss() string {
pub fn (t Time) hhmmss() string {
return '${t.hour:02d}:${t.minute:02d}:${t.second:02d}'
}
// 2012-01-05
fn (t Time) ymmdd() string {
pub fn (t Time) ymmdd() string {
return '${t.year}-${t.month:02d}-${t.day:02d}'
}
// Jul 3
fn (t Time) md() string {
pub fn (t Time) md() string {
// jl := t.smonth()
s := '${t.smonth()} $t.day'
return s
@ -151,7 +151,7 @@ pub fn (t Time) clean() string {
// return fmt.Sprintf("%4d/%02d/%02d", t.Year(), t.Month(), t.Day()) + " " + hm
}
fn (t Time) clean12() string {
pub fn (t Time) clean12() string {
nowe := time.now()
// if amtime {
// hm = t.Format("3:04 pm")
@ -172,12 +172,6 @@ fn (t Time) clean12() string {
// return fmt.Sprintf("%4d/%02d/%02d", t.Year(), t.Month(), t.Day()) + " " + hm
}
/*
// in ms
fn ticks() double {
return 0
}
*/
// `parse` parses time in the following format: "2018-01-27 12:48:34"
pub fn parse(s string) Time {
// println('parse="$s"')
@ -208,11 +202,11 @@ pub fn parse(s string) Time {
})
}
fn new_time(t Time) Time {
pub fn new_time(t Time) Time {
return{t | uni: t.calc_unix()}
}
fn (t &Time) calc_unix() int {
pub fn (t &Time) calc_unix() int {
if t.uni != 0 {
return t.uni
}
@ -263,7 +257,7 @@ pub fn (t Time) relative() string {
return t.md()
}
fn day_of_week(y, m, d int) int {
pub fn day_of_week(y, m, d int) int {
// TODO please no
//# return (d += m < 3 ? y-- : y - 2, 23*m/9 + d + 4 + y/4- y/100 + y/400)%7;
return 0
@ -278,3 +272,39 @@ pub fn (t Time) weekday_str() string {
i := t.day_of_week() - 1
return Days.substr(i * 3, (i + 1) * 3)
}
// in ms
pub fn ticks() f64 {
$if windows {
return C.GetTickCount()
}
panic('not implemented')
/*
t := i64(C.mach_absolute_time())
# Nanoseconds elapsedNano = AbsoluteToNanoseconds( *(AbsoluteTime *) &t );
# return (double)(* (uint64_t *) &elapsedNano) / 1000000;
*/
return f64(0)
}
pub fn sleep(seconds int) {
$if windows {
C._sleep(seconds * 1000)
}
$else {
C.sleep(seconds)
}
}
pub fn usleep(n int) {
C.usleep(n)
}
pub fn sleep_ms(n int) {
$if windows {
C.Sleep(n)
}
$else {
C.usleep(n * 1000)
}
}

View File

@ -1,19 +0,0 @@
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module time
// in ms
pub fn ticks() f64 {
return f64(0)
}
pub fn sleep(seconds int) {
C.sleep(seconds)
}
pub fn sleep_ms(seconds int) {
C.usleep(seconds * 1000)
}

View File

@ -1,33 +0,0 @@
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module time
//#flag -framework CoreServices
//#include <CoreServices/CoreServices.h>
//#include <mach/mach_time.h>
// in ms
pub fn ticks() f64 {
panic('not implemented')
/*
t := i64(C.mach_absolute_time())
# Nanoseconds elapsedNano = AbsoluteToNanoseconds( *(AbsoluteTime *) &t );
# return (double)(* (uint64_t *) &elapsedNano) / 1000000;
*/
return f64(0)
}
pub fn sleep(seconds int) {
C.sleep(seconds)
}
pub fn usleep(seconds int) {
C.usleep(seconds)
}
pub fn sleep_ms(seconds int) {
C.usleep(seconds * 1000)
}

View File

@ -1,24 +0,0 @@
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module time
// in ms
fn ticks() double {
return C.GetTickCount()
}
fn sleep(seconds int) {
C._sleep(seconds * 1000)
}
fn usleep(seconds int) {
panic('usleep not impl')
// C._usleep(seconds)
}
fn sleep_ms(n int) {
C.Sleep(n)
}