Skip to content

Commit

Permalink
Merge pull request #30 from sibidass/zonesort
Browse files Browse the repository at this point in the history
  • Loading branch information
ibLeDy authored Oct 13, 2021
2 parents e17aaf7 + 5297394 commit 1e8b555
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions timezone_converter/comparison_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(
timezones: List[str],
zone: bool,
hour: Union[int, None],
order: bool,
) -> None:
self.zone = zone
self.hour = hour
Expand All @@ -37,6 +38,15 @@ def __init__(
)
self.midnights.append(foreign_midnight)

if order:
self._sort_timezone_display()

def _sort_timezone_display(self) -> None:
local_offset = int(self.midnights[0].strftime('%z'))
self.midnights.sort(
key=lambda zone: abs(local_offset - int(zone.strftime('%z'))),
)

def _get_timezone_name(self, timezone: str) -> str:
timezone_name = self.timezone_translations.get(timezone.lower())
if timezone_name is None:
Expand Down
7 changes: 7 additions & 0 deletions timezone_converter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def build_parser() -> argparse.ArgumentParser:
metavar='WORD',
help='fuzzy search for a timezone',
)
parser.add_argument(
'-o',
'--order',
action='store_true',
help='show timezones in order of difference',
)

return parser

Expand All @@ -97,6 +103,7 @@ def main() -> int:
args.timezone,
args.zone,
args.hour,
args.order,
).print_table()
else:
parser.print_help()
Expand Down

0 comments on commit 1e8b555

Please sign in to comment.