Advertisement
Guest User

Untitled

a guest
Apr 21st, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import datetime as dt
  2. from typing import List
  3.  
  4.  
  5. def split_int_string(digits: str, *at: int) -> List[int]:
  6.     """
  7.    Split a string at given indices and parse the parts to int.
  8.    """
  9.     # Make a canonical representation.
  10.     split: List[int] = sorted(at)
  11.     if not split or split[0] != 0:
  12.         split.insert(0, 0)
  13.     if split[-1] != len(digits):
  14.         split.append(len(digits))
  15.     return [int(digits[split[i - 1] : split[i]]) for i in range(1, len(split))]
  16.  
  17.  
  18. date = "20210421"
  19. time = "235930"
  20. print(
  21.     f"date '{date}' and time '{time}' gives:",
  22.     dt.datetime(*split_int_string(date, 4, 6, 8), *split_int_string(time, 2, 4)),
  23. )
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement