lib.time
1from typing import Literal 2from datetime import datetime 3 4 5YEAR = datetime.now().year 6"""Current year as integer, e.g. `2026`.""" 7MM_DD = datetime.now().strftime("%m-%d") 8"""Current month and day in string format, e.g. `06-14`.""" 9 10 11def getDate(format: Literal["machine", "human"], includeYear: bool = True) -> str: 12 """Get current date in specified format. Include year if `includeYear` is `True` (default). 13 14 Example: 15 - `machine` => `2026-06-14` 16 - `human` => `Jun 14, 2026` 17 """ 18 now = datetime.now() 19 if format == "machine": 20 return now.strftime("%Y-%m-%d" if includeYear else "%m-%d") 21 else: 22 return now.strftime("%b %d, %Y" if includeYear else "%b %d") 23 24 25def getTime(clock: Literal["12-hour", "24-hour"], includeSeconds: bool) -> str: 26 """Get current time in specified format. Include seconds if `includeSeconds` is `True`. 27 28 Example: 29 - `12-hour` => `03:45 PM` 30 - `24-hour` => `15:45` 31 """ 32 now = datetime.now() 33 if clock == "12-hour": 34 timeFormat = "%I:%M %p" if not includeSeconds else "%I:%M:%S %p" 35 else: 36 timeFormat = "%H:%M" if not includeSeconds else "%H:%M:%S" 37 return now.strftime(timeFormat)
YEAR =
2026
Current year as integer, e.g. 2026.
MM_DD =
'06-08'
Current month and day in string format, e.g. 06-14.
def
getDate(format: Literal['machine', 'human'], includeYear: bool = True) -> str:
12def getDate(format: Literal["machine", "human"], includeYear: bool = True) -> str: 13 """Get current date in specified format. Include year if `includeYear` is `True` (default). 14 15 Example: 16 - `machine` => `2026-06-14` 17 - `human` => `Jun 14, 2026` 18 """ 19 now = datetime.now() 20 if format == "machine": 21 return now.strftime("%Y-%m-%d" if includeYear else "%m-%d") 22 else: 23 return now.strftime("%b %d, %Y" if includeYear else "%b %d")
Get current date in specified format. Include year if includeYear is True (default).
Example:
machine=>2026-06-14human=>Jun 14, 2026
def
getTime(clock: Literal['12-hour', '24-hour'], includeSeconds: bool) -> str:
26def getTime(clock: Literal["12-hour", "24-hour"], includeSeconds: bool) -> str: 27 """Get current time in specified format. Include seconds if `includeSeconds` is `True`. 28 29 Example: 30 - `12-hour` => `03:45 PM` 31 - `24-hour` => `15:45` 32 """ 33 now = datetime.now() 34 if clock == "12-hour": 35 timeFormat = "%I:%M %p" if not includeSeconds else "%I:%M:%S %p" 36 else: 37 timeFormat = "%H:%M" if not includeSeconds else "%H:%M:%S" 38 return now.strftime(timeFormat)
Get current time in specified format. Include seconds if includeSeconds is True.
Example:
12-hour=>03:45 PM24-hour=>15:45