`time` module does not translate well!
See original GitHub issueDescribe the bug
when using methods from the time
module, the only method that is translated properly is time.sleep()
, while the others result the same python code in Go.
Python code example
import time
def main():
print(time.time())
print(time.time_ns())
print(time.ctime(time.time()))
if __name__ == '__main__':
main()
Current behavior the above three methods are not being translated into Go code but rather written as is in python, and this code is generated. which is not a valid Go code!
package main
import "fmt"
func main() {
fmt.Println(time.time())
fmt.Println(time.time_ns())
fmt.Println(time.ctime(time.time()))
}
Expected behavior
time.time()
should be translated intotime.Now().Unix()
in Gotime.time_ns()
should be translated intotime.Now().UnixNano()
in Gotime.ctime(time.time())
should be translated intotime.Now()
in Go
Correct Go code example
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println(time.Now().Unix())
fmt.Println(time.Now().UnixNano())
fmt.Println(time.Now())
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Lazy-loaded modules dont get their translations when "isolate ...
When "isolate" is true the file is correctly loaded but the module doesn't have access to previously loaded translations. Expected behavior.
Read more >A Beginner's Guide to the Python time Module
Python's time module provides a function for getting local time from the number of seconds elapsed since the epoch called localtime() . Notice...
Read more >Installing a module causes translations to be overwritten
e) Go to admin/modules and install the core Activity Tracker module. Translations are imported. Note: I have no idea why translations would be ......
Read more >trying to convert a whole column from Spanish to English, with ...
I'm trying to convert a column containing Spanish tweets (removi stop words, tokenize and stemming process were done) to English with the ...
Read more >Module 3: Translation Cost and Turnaround Times
When you kick off ("authorize") a new translation request, you can select not only the required target languages, but also the preferred workflow...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
aha, I thought
time.time()
returns an int in python. my bad 😅@mbaraa But they return different types, I believe.
https://pkg.go.dev/time#Time.Unix - int64 (second precision) https://docs.python.org/3/library/time.html#time.time - float (precision better than 1 second on most systems)
I agree it’s a bit weird but I’m not sure of a better way to get nanosecond precision on a float like Python does. Example where this kinda matters:
If you want that to print approximately 0.5 in Go, you’d need to preserve that information right?
I could add an explicit case for int(time.time()) to simplify it to time.Now().Unix()