I am not sure if that is already included in tm1py. I found nothing so far.
I wrote a little helper to convert a timestamp into the serial number format for tm1 to load it directly as numeric value into a cube.
Should we include something like that or is it maybe already included?
````python
def getTM1TimeValueNow():
# timestamp according to tm1
start = datetime(1960, 1, 1, 00, 00, 0000)
now = datetime.now()
#get dates
days = (now - start).days
#get time
time = now.hour /24 + now.minute / 60 / 24 + now.second / 60 / 60 / 24
ts= days+ time
return ts
````
Hi @scrumthing,
We don't have a function for this in TM1py yet.
Please create a PR to include it in the Utils module.
Please also rename the function to get_tm1_time_value_now and add a few simple tests to the Tests/Utils.py module
I think we also have to cover the case that UseExcelSerialDate is set to T in the tm1s.cfg. Perhaps you can add an optional argument to the function: use_excel_serial_data to use the excel origin date instead of 1960-01-01.
Thanks!
why not! just added some makeup here and there...
def get_tm1_time_value_now(use_excel_serial_data: bool = False) -> float:
"""
This function can be used to replicate TM1's NOW function
to return current date/time value in serial number format.
:param use_excel_serial_data: Boolean
:return: serial number
"""
from datetime import datetime
# timestamp according to tm1
start_datetime = datetime(1899, 12, 30) if use_excel_serial_data else datetime(1960, 1, 1)
current_datetime = datetime.now()
delta = current_datetime - start_datetime
return delta.days + (delta.seconds / 86400)
Yeah, that is exactly like I would have done it. Thanks @rkvinoth! Since you wrote it, you could be so kind to add the requested tests and create the PR. ;-)
Oh man I got caught here! 馃槃
Sure, will do it once I have some time.
Most helpful comment
why not! just added some makeup here and there...