DeaD_EyE icon

strange dates

DeaD_EyE | PRO | 03/07/22 11:53:48 PM UTC | 0 ⭐ | 1806 👁️ | Never ⏰ | []
Python |

1.63 KB

|

None

|

0 👍

/

0 👎

from dataclasses import dataclass, field
from datetime import datetime as Date
 
from rich import get_console
from rich.table import Table
 
 
@dataclass
class War:
    name: str
    entry_date: Date
 
    @property
    def date_sum(self):
        day = self.entry_date.day
        month = self.entry_date.month
        century = self.entry_date.year // 100
        decade = self.entry_date.year % 100
        return day + month + century + decade
 
    @property
    def row(self):
        return self.name, self.entry_date.strftime("%Y-%m-%d"), str(self.date_sum)
 
 
wars = [
    War("World War 1", Date(1914, 7, 28)),
    War("World War 2", Date(1939, 9, 1)),
    War('"Official" Ukraine War', Date(2022, 2, 24)),
]
 
console = get_console()
table = Table()
table.add_column("Name")
table.add_column("Entry date")
table.add_column("Date Sum")
 
for war in wars:
    table.add_row(*war.row)
 
 
console.print(table)
 
# output
"""
┏━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Name                   ┃ Entry date ┃ Date Sum ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩
│ World War 1            │ 1914-07-28 │ 68       │
│ World War 2            │ 1939-09-01 │ 68       │
│ "Official" Ukraine War │ 2022-02-24 │ 68       │
└────────────────────────┴────────────┴──────────┘
"""

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎