Skip to content

Commit

Permalink
[osh] Store timestamps as floats internally
Browse files Browse the repository at this point in the history
Round to integer after subtracting.  I think this is slightly more
accurate in theory.
  • Loading branch information
Andy C committed Jan 24, 2024
1 parent 064800a commit 5345265
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions core/state.py
Expand Up @@ -1056,7 +1056,7 @@ def __init__(self, dollar0, argv, arena, debug_stack):
self.debug_stack = debug_stack

self.pwd = None # type: Optional[str]
self.seconds_start = int(time_.time()) # int
self.seconds_start = time_.time()

self.token_for_line = None # type: Optional[Token]
self.loc_for_expr = loc.Missing # type: loc_t
Expand Down Expand Up @@ -1102,10 +1102,6 @@ def SetPwd(self, pwd):
"""Used by builtins."""
self.pwd = pwd

def GetSeconds(self):
# type: () -> int
return int(time_.time()) - self.seconds_start

def ParsingChangesAllowed(self):
# type: () -> bool
"""For checking that syntax options are only used at the top level."""
Expand Down Expand Up @@ -1954,7 +1950,7 @@ def GetValue(self, name, which_scopes=scope_e.Shopt):
return value.Str(self.last_arg)

if name == 'SECONDS':
seconds = self.GetSeconds()
seconds = int(time_.time() - self.seconds_start)
return value.Int(seconds)

# In the case 'declare -n ref='a[42]', the result won't be a cell. Idea to
Expand Down

0 comments on commit 5345265

Please sign in to comment.