//
//  Foundation+.swift
//  IOS_study
//
//  Created by CC-star on 2025/6/29.
//

import Foundation


extension String {
   var isBlank: Bool {
      self.isEmpty || self.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty//没有输入或者输入空格
   }
   var trimmed: String {
      self.trimmingCharacters(in: .whitespacesAndNewlines)
   }
}

extension Date {
   var daysFromNow: Int {
      Calendar.current.dateComponents([.day], from: self, to: .now).day ?? 0//??空合运算符
   }
   
   
   
   //   let date = Date()
   //   print(date.string(withFormat: "yyyy/MM/dd HH:mm")) // 2023/08/24 16:21
   //   print(date.string(withFormat: "yyyy/MM/dd hh:mm")) // 2023/08/24 04:21
   var toStr: String {
      let year = Calendar.current.component(.year, from: self)
      let currentYear = Calendar.current.component(.year, from: Date())
      let dateFormatter = DateFormatter()
      dateFormatter.dateFormat = (year == currentYear) ? "M-d" : "yyyy-M-d"
      return dateFormatter.string(from: self)
   }

   
}


