Skip to content

Commit

Permalink
Merge pull request #10 from bluedenim/consistent_date_format_for_records
Browse files Browse the repository at this point in the history
standardize the date format for display so that naive and aware dates are printed consistently
  • Loading branch information
bluedenim authored Jul 4, 2021
2 parents 7833bac + bf2fd7f commit aa7be6c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "vmigration-helper"
version = "0.0.12"
version = "0.0.13"
homepage = "https://github.com/bluedenim/vmigration-helper"
description = "Van's Django Migration Helper"
authors = ["bluedenim <vancly@hotmail.com>"]
Expand Down
9 changes: 6 additions & 3 deletions vmigration_helper/management/commands/migration_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

FORMAT_CSV = 'csv'
FORMAT_CONSOLE = 'console'
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S%z'


class Command(BaseCommand):
Expand All @@ -17,19 +18,21 @@ class Command(BaseCommand):

@staticmethod
def _format_csv(record: MigrationRecorder.Migration) -> str:
return f"{record.id},{record.applied.isoformat()},{record.app},{record.name}"
return f"{record.id},{record.applied.strftime(DATETIME_FORMAT)},{record.app},{record.name}"

@staticmethod
def _format_console(record: MigrationRecorder.Migration, app_name_width: int) -> str:
return (
f"{str(record.id).rjust(6, ' ')} {record.applied.isoformat()} "
f"{str(record.id).rjust(6, ' ')} {record.applied.strftime(DATETIME_FORMAT).ljust(24, ' ')} "
f"{record.app.rjust(app_name_width, ' ')} {record.name}"
)

@staticmethod
def _format_header_console(app_name_width: int) -> str:
# alloc width 6 for IDs
# alloc width 24 for the date: YYYY-MM-DDTHH:MM:SSZZZZZ (DATETIME_FORMAT)
return (
f"{'ID'.rjust(6, ' ')} {'Applied'.ljust(32, ' ')} "
f"{'ID'.rjust(6, ' ')} {'Applied'.ljust(24, ' ')} "
f"{'App'.rjust(app_name_width, ' ')} Name"
)

Expand Down

0 comments on commit aa7be6c

Please sign in to comment.