( newestDate: Date | undefined )
| 91 | * @returns Trend classification |
| 92 | */ |
| 93 | export function calculateTrend( |
| 94 | newestDate: Date | undefined |
| 95 | ): 'Rising' | 'Declining' | 'Stable' | undefined { |
| 96 | if (!newestDate) return undefined; |
| 97 | |
| 98 | const now = new Date(); |
| 99 | const daysDiff = Math.floor((now.getTime() - newestDate.getTime()) / (1000 * 60 * 60 * 24)); |
| 100 | |
| 101 | if (daysDiff <= 60) return 'Rising'; |
| 102 | if (daysDiff >= 180) return 'Declining'; |
| 103 | return 'Stable'; |
| 104 | } |