Source code for polaris.ocean.model.time

import time


[docs]def get_time_interval_string(days=None, seconds=None): """ Convert a time interval in days and/or seconds to a string for use in a model config option. If both are provided, they will be added Parameters ---------- days : float, optional A time interval in days seconds : float, optional A time interval in seconds Returns ------- time_str : str The time as a string in the format "DDDD_HH:MM:SS.SS" """ sec_per_day = 86400 total = 0. if seconds is not None: total += seconds if days is not None: total += sec_per_day * days day_part = int(total / sec_per_day) sec_part = total - day_part * sec_per_day # https://stackoverflow.com/a/1384565/7728169 seconds_str = time.strftime('%H:%M:%S', time.gmtime(sec_part)) time_str = f'{day_part:04d}_{seconds_str}' return time_str