Commit a9e1e0de authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

add TimeStamp

parent f46b435d
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
import datetime

from astropy import time


def now():
    """ Return ISOT8601 format datetime, for time stamps in data products. """
@@ -9,3 +11,16 @@ def now():
def now_dfs():
    """ Return ISOT8601 format datetime, for DFS usage only. """
    return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')


class TimeStamp:
    def __init__(self, file_path=""):
        self.file_path = file_path

    def truncate(self):
        with open(self.file_path, 'w') as file:
            file.truncate(0)

    def punch_in(self):
        with open(self.file_path, "a+") as f:
            f.write(f"{time.Time.now().isot}+00:00\n")