@@ -2032,6 +2032,49 @@ def test_multiple_granularity(self):
2032
2032
== "a minute and 2 seconds ago"
2033
2033
)
2034
2034
2035
+ def test_all_granularity (self ):
2036
+ assert (
2037
+ self .now .humanize (granularity = "all" )
2038
+ == "in 0 years 0 months 0 weeks 0 days 0 hours 0 minutes and 0 seconds"
2039
+ ) # TODO: this should be "ago"; change this when #997 is merged
2040
+
2041
+ later105 = self .now .shift (seconds = 10 ** 5 )
2042
+ assert (
2043
+ self .now .humanize (later105 , granularity = "all" )
2044
+ == "0 years 0 months 0 weeks a day 3 hours 46 minutes and 40 seconds ago"
2045
+ )
2046
+ assert (
2047
+ later105 .humanize (self .now , granularity = "all" )
2048
+ == "in 0 years 0 months 0 weeks a day 3 hours 46 minutes and 40 seconds"
2049
+ )
2050
+
2051
+ later108 = self .now .shift (seconds = 10 ** 8 )
2052
+ assert (
2053
+ self .now .humanize (later108 , granularity = "all" )
2054
+ == "3 years 2 months 0 weeks a day 9 hours 46 minutes and 40 seconds ago"
2055
+ )
2056
+ assert (
2057
+ later108 .humanize (self .now , granularity = "all" )
2058
+ == "in 3 years 2 months 0 weeks a day 9 hours 46 minutes and 40 seconds"
2059
+ )
2060
+ assert (
2061
+ self .now .humanize (later108 , granularity = "all" , only_distance = True )
2062
+ == "3 years 2 months 0 weeks a day 9 hours 46 minutes and 40 seconds"
2063
+ )
2064
+
2065
+ later_two_months = self .now .shift (months = 2 )
2066
+ assert (
2067
+ self .now .humanize (later_two_months , granularity = "all" )
2068
+ == "in 0 years 2 months 0 weeks 0 days 0 hours 0 minutes and 0 seconds"
2069
+ ) # TODO: this should be "ago"; change this when #997 is merged
2070
+ assert (
2071
+ later_two_months .humanize (self .now , granularity = "all" )
2072
+ == "in 0 years 2 months 0 weeks 0 days 0 hours 0 minutes and 0 seconds"
2073
+ )
2074
+
2075
+ with pytest .raises (ValueError ):
2076
+ self .now .humanize (later108 , granularity = ["all" , "year" ])
2077
+
2035
2078
def test_seconds (self ):
2036
2079
2037
2080
later = self .now .shift (seconds = 10 )
0 commit comments