48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""
|
|
timestamp string checks
|
|
"""
|
|
|
|
from corelibs.string_handling.timestamp_strings import convert_to_seconds, TimeParseError, TimeUnitError
|
|
|
|
|
|
def main() -> None:
|
|
"""
|
|
Comment
|
|
"""
|
|
test_cases = [
|
|
"5M 6d", # 5 months, 6 days
|
|
"2h 30m 45s", # 2 hours, 30 minutes, 45 seconds
|
|
"1Y 2M 3d", # 1 year, 2 months, 3 days
|
|
"1h", # 1 hour
|
|
"30m", # 30 minutes
|
|
"2 hours 15 minutes", # 2 hours, 15 minutes
|
|
"1d 12h", # 1 day, 12 hours
|
|
"3M 2d 4h", # 3 months, 2 days, 4 hours
|
|
"45s", # 45 seconds
|
|
"1 year 2 months", # 1 year, 2 months
|
|
"2Y 6M 15d 8h 30m 45s", # Complex example
|
|
# ]
|
|
# invalid_test_cases = [
|
|
"5M 6d 2M", # months appears twice
|
|
"2h 30m 45s 1h", # hours appears twice
|
|
"1d 2 days", # days appears twice (short and long form)
|
|
"30m 45 minutes", # minutes appears twice
|
|
"1Y 2 years", # years appears twice
|
|
"1x 2 yrs", # invalid names
|
|
]
|
|
|
|
for time_string in test_cases:
|
|
try:
|
|
result = convert_to_seconds(time_string)
|
|
print(f"{time_string} => {result}")
|
|
except (TimeParseError, TimeUnitError) as e:
|
|
print(f"Error encountered for {time_string}: {type(e).__name__}: {e}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
# __END__
|