From 9c92f4e5fc8cc6a37b51b41dff36d549deb8872d Mon Sep 17 00:00:00 2001 From: Deimos Date: Wed, 13 Nov 2019 00:04:47 -0700 Subject: [PATCH] Add thousands separator for word counts >= 10000 --- tildes/tildes/enums.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tildes/tildes/enums.py b/tildes/tildes/enums.py index 57a66ae..2b87ced 100644 --- a/tildes/tildes/enums.py +++ b/tildes/tildes/enums.py @@ -118,12 +118,6 @@ class ContentMetadataFields(enum.Enum): def format_value(self, value: Any) -> str: """Format a value stored in this field into a string for display.""" - if self.name == "WORD_COUNT": - if value == 1: - return "1 word" - - return f"{value} words" - if self.name == "DURATION": delta = timedelta(seconds=value) @@ -141,6 +135,18 @@ class ContentMetadataFields(enum.Enum): date_str = published.strftime("%b %-d %Y") return f"published {date_str}" + if self.name == "WORD_COUNT": + if value == 1: + return "1 word" + + if value >= 10_000: + # dirty way of using non-breaking thin spaces as thousands separators + word_count = f"{value:,}".replace(",", "\u202F") + else: + word_count = str(value) + + return f"{word_count} words" + return str(value)