<commit_before>//
//  ContestFormatter.swift
//  JumuNordost
//
//  Created by <NAME> on 24/02/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

struct FormattedContest {
    let name: String
    let dates: String
}

class ContestFormatter {

    private static let dateFormatter: NSDateFormatter = {
        let formatter = NSDateFormatter()
        formatter.dateStyle = .LongStyle
        formatter.timeStyle = .NoStyle
        formatter.locale = NSLocale.autoupdatingCurrentLocale()
        return formatter
    }()

    // MARK: - Formatting

    static func formattedContest(contest: Contest) -> FormattedContest {

        dateFormatter.timeZone = contest.timeZone // TODO: Eliminate this state

        let (startDate, endDate) = (contest.startDate, contest.endDate)

        let dates: String = {
            if startDate == endDate {
                return dateFormatter.stringFromDate(startDate)
            } else {
                return [startDate, endDate].map(dateFormatter.stringFromDate).joinWithSeparator(" – ")
            }
        }()

        return FormattedContest(
            name: contest.name,
            dates: dates
        )
    }
}<commit_msg>Use awesome NSDateIntervalFormatter to format contest dates in list<commit_after>//
//  ContestFormatter.swift
//  JumuNordost
//
//  Created by <NAME> on 24/02/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

struct FormattedContest {
    let name: String
    let dates: String
}

class ContestFormatter {

    private static let dateIntervalFormatter: NSDateIntervalFormatter = {
        let formatter = NSDateIntervalFormatter()
        formatter.dateStyle = .LongStyle
        formatter.timeStyle = .NoStyle
        formatter.locale = NSLocale.autoupdatingCurrentLocale()
        return formatter
    }()

    // MARK: - Formatting

    static func formattedContest(contest: Contest) -> FormattedContest {

        dateIntervalFormatter.timeZone = contest.timeZone // TODO: Eliminate this state

        return FormattedContest(
            name: contest.name,
            dates: dateIntervalFormatter.stringFromDate(contest.startDate, toDate: contest.endDate)
        )
    }
}
{'fraction_non_alphanumeric': 0.08943089430894309, 'fraction_numerical': 0.009033423667570008, 'mean_word_length': 2.4609375, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '2393323', 'n_tokens_mistral': 641, 'n_tokens_neox': 595, 'n_words': 152}