<commit_before>//  Created by dasdom on 12.04.20.
//  Copyright © 2020 dasdom. All rights reserved.
//

import Foundation

public struct BirthdayCountdown : Hashable {
  public let name: String
  public let remainingDays: Int
  public let birthday: Birthday
  public let age: Int
  
  public init(birthday: Birthday) {
    
    // https://stackoverflow.com/a/31132581/498796
    let calendar = Calendar(identifier: .gregorian)
    let date = Date(timeIntervalSinceNow: -24 * 60 * 60)
    let yesterday = calendar.startOfDay(for: date)
    let today = calendar.startOfDay(for: Date())
    let birthdayComponents = calendar.dateComponents([.day, .month], from: birthday.date)
    let nextBirthday = calendar.nextDate(after: yesterday, matching: birthdayComponents, matchingPolicy: .nextTimePreservingSmallerComponents)
    
    guard let daysCount = calendar.dateComponents([.day], from: today, to: nextBirthday!).day else {
      fatalError()
    }
    
    guard let age = calendar.dateComponents([.year], from: birthday.date, to: today).year else {
      fatalError()
    }
    
    name = birthday.name
    remainingDays = daysCount-1
    self.birthday = birthday
    self.age = age
  }
}<commit_msg>Fix problem again ...<commit_after>//  Created by dasdom on 12.04.20.
//  Copyright © 2020 dasdom. All rights reserved.
//

import Foundation

public struct BirthdayCountdown : Hashable {
  public let name: String
  public let remainingDays: Int
  public let birthday: Birthday
  public let age: Int
  
  public init(birthday: Birthday) {
    
    // https://stackoverflow.com/a/31132581/498796
    let calendar = Calendar(identifier: .gregorian)
    let date = Date(timeIntervalSinceNow: -24 * 60 * 60)
    let yesterday = calendar.startOfDay(for: date)
    let today = calendar.startOfDay(for: Date())
    let birthdayComponents = calendar.dateComponents([.day, .month], from: birthday.date)
    let nextBirthday = calendar.nextDate(after: yesterday, matching: birthdayComponents, matchingPolicy: .nextTimePreservingSmallerComponents)
    
    guard let daysCount = calendar.dateComponents([.day], from: today, to: nextBirthday!).day else {
      fatalError()
    }
    
    guard let age = calendar.dateComponents([.year], from: birthday.date, to: today).year else {
      fatalError()
    }
    
    name = birthday.name
    remainingDays = daysCount
    self.birthday = birthday
    self.age = age
  }
}
{'fraction_non_alphanumeric': 0.1037344398340249, 'fraction_numerical': 0.025311203319502075, 'mean_word_length': 3.3363309352517985, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2221682', 'n_tokens_mistral': 760, 'n_tokens_neox': 704, 'n_words': 201}