sot / chandra_time

Convert between various time formats relevant to Chandra.
https://sot.github.io/Chandra.Time
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

Problem converting greta format times with zero hrs mins secs #7

Closed mbaski closed 11 years ago

mbaski commented 11 years ago

Entering a time in greta format works great, except when the digits to the right of the decimal place are zero, where an error is raised: ChandraTimeError: Invalid input format 'greta'

Here is an example:

In [1]: from Chandra.Time import DateTime

In [2]: sometime = DateTime(2013055.121212123,format='greta')

In [3]: print sometime.date 2013:055:12:12:12.123

In [4]: sometime = DateTime(2013055.000000000,format='greta')

In [5]: print sometime.date

ChandraTimeError Traceback (most recent call last)

in () ----> 1 print sometime.date C:\Users\mbaski\Documents\Baski_Data\Chandra\MATLAB\FOT_Tools\Python\python_Windows_64bit\lib\site-packages\chandra.time-1.14-py2.7-win-amd64.egg\Chandra\Time.pyc in **getattr**(self, fmt_out) 579 return convert(self.time_in, 580 fmt_in=self.format, --> 581 fmt_out=fmt_out, 582 ) 583 C:\Users\mbaski\Documents\Baski_Data\Chandra\MATLAB\FOT_Tools\Python\python_Windows_64bit\lib\site-packages\chandra.time-1.14-py2.7-win-amd64.egg\Chandra\Time.pyc in convert(time_in, sys_in, fmt_in, sys_out, fmt_out) 500 return [_convert(x, sys_in, fmt_in, sys_out, fmt_out) for x in time_in] 501 except TypeError: --> 502 return _convert(time_in, sys_in, fmt_in, sys_out, fmt_out) 503 504 def _convert(time_in, sys_in, fmt_in, sys_out, fmt_out): C:\Users\mbaski\Documents\Baski_Data\Chandra\MATLAB\FOT_Tools\Python\python_Windows_64bit\lib\site-packages\chandra.time-1.14-py2.7-win-amd64.egg\Chandra\Time.pyc in _convert(time_in, sys_in, fmt_in, sys_out, fmt_out) 524 break 525 else: --> 526 raise ChandraTimeError, "Invalid input format '%s'" % fmt_in 527 528 if sys_in: ChandraTimeError: Invalid input format 'greta'
taldcroft commented 11 years ago

@mbaski, @jeanconn - code is now attached to this issue. Can you give this branch a try in your environment before I merge?

mbaski commented 11 years ago

@taldcroft, @jeanconn - Fixes the issue and works great in my Windows environment.