Sciris dates

From sciris/sciris · View interactive version

Sciris dates is an AI agent skill from the GitHub repository sciris/sciris. Use when working with dates, times, or timing in Sciris — sc.timer, sc.tic, sc.toc, sc.date, sc.daterange, sc.datedelta, sc.now, sc.getdate, sc.time, sc.timedsleep, sc.randsleep, date format conversion, or timing code blocks.

How to use this skill

Skill file

Sciris Dates and Times

Reference for timing and date utilities. See full tutorial: docs/tutorials/tut_dates.ipynb.

If you need more detail, use your MCP tools (Context7 or GitMCP) to look up current Sciris documentation, or consult the other Sciris skills.

Timing Code

Timer object

T = sc.timer()

zeros = np.zeros((n, n))
T.tt('Make zeros')          # toc-then-tic (prints elapsed, resets)

rand = np.random.rand(n, n)
T.tt('Make random')

Context manager

with sc.timer('My operation'):
    expensive_work()

Timer statistics

T = sc.timer()
for i in range(10):
    work(i)
    T.tt(f'Iteration {i}')

print(T.mean(), T.std(), T.min(), T.max())
T.plot()                    # Plot timing results

Sleep Utilities

sc.timedsleep(0.3)                  # Like time.sleep()

# In a loop: accounts for computation time so each iteration = exact duration
for i in range(5):
    sc.timedsleep('start')
    do_work()
    sc.timedsleep(0.3, verbose=True)  # Total iteration = 0.3s

sc.randsleep(0.2)                    # Sleep random 0-0.4s (mean 0.2)

Date Utilities

Current time

sc.time()                # Unix timestamp (time.time())
sc.now()                 # datetime.datetime.now()
sc.getdate()             # Formatted string: '2024-Mar-15 14:30:00'

Date conversion

sc.date('2022-03-04')                        # str → datetime
sc.date('04-03-2022', format='mdy')          # Explicit format
sc.date('04-03-2022', format='dmy')          # Day-month-year

Date ranges and math

dates = sc.daterange('2022-02-02', '2022-03-04')          # List of date strings
dates = sc.daterange('2022-01-01', '2022-12-31', as_date=True)  # As datetime objects
newdates = sc.datedelta(dates, months=10)                  # Add 10 months
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.