Switch if/elif/else to use pattern matching instead
This commit is contained in:
		
							parent
							
								
									44fcf46178
								
							
						
					
					
						commit
						05453e8f1a
					
				| 
						 | 
					@ -40,28 +40,27 @@ def format_time(time_str: str, net_precision: str) -> tuple[str, str | None]:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    include_time = False
 | 
					    include_time = False
 | 
				
			||||||
    # Format the date based on precision
 | 
					    # Format the date based on precision
 | 
				
			||||||
    time_format: str | None = None
 | 
					    time_format: str | None
 | 
				
			||||||
    field2 = None
 | 
					    field2 = None
 | 
				
			||||||
    if net_precision == "Year":
 | 
					
 | 
				
			||||||
 | 
					    match net_precision:
 | 
				
			||||||
 | 
					        case "Year":
 | 
				
			||||||
            time_format = "%Y"
 | 
					            time_format = "%Y"
 | 
				
			||||||
    if net_precision == "Month":
 | 
					        case "Month":
 | 
				
			||||||
            time_format = "%b %Y"
 | 
					            time_format = "%b %Y"
 | 
				
			||||||
    if net_precision == "Week":
 | 
					        case "Week":
 | 
				
			||||||
            time_format = "%d %b %Y"
 | 
					            time_format = "%d %b %Y"
 | 
				
			||||||
            field2 = "(Week of)"
 | 
					            field2 = "(Week of)"
 | 
				
			||||||
    if net_precision == "Day":
 | 
					        case "Day" | "Hour" | "Minute":
 | 
				
			||||||
            time_format = "%d %b %Y"
 | 
					            time_format = "%d %b %Y"
 | 
				
			||||||
    if net_precision == "Hour":
 | 
					            include_time = net_precision in {"Hour", "Minute"}
 | 
				
			||||||
 | 
					        case "Second":
 | 
				
			||||||
            time_format = "%d %b %Y"
 | 
					            time_format = "%d %b %Y"
 | 
				
			||||||
            include_time = True
 | 
					            include_time = True
 | 
				
			||||||
    if net_precision == "Minute":
 | 
					        case _ if net_precision.startswith("Quarter "):
 | 
				
			||||||
        time_format = "%d %b %Y"
 | 
					 | 
				
			||||||
        include_time = True
 | 
					 | 
				
			||||||
    elif net_precision == "Second":
 | 
					 | 
				
			||||||
        time_format = "%d %b %Y"
 | 
					 | 
				
			||||||
        include_time = True
 | 
					 | 
				
			||||||
    elif net_precision.startswith("Quarter "):
 | 
					 | 
				
			||||||
            time_format = f"Q{net_precision[-1]} %Y"
 | 
					            time_format = f"Q{net_precision[-1]} %Y"
 | 
				
			||||||
 | 
					        case _:
 | 
				
			||||||
 | 
					            time_format = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if not time_format:
 | 
					    if not time_format:
 | 
				
			||||||
        return (repr(time_str), repr(net_precision))
 | 
					        return (repr(time_str), repr(net_precision))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue