<commit_before>package com.acornui.jvm.time

import com.acornui.core.UserInfo
import com.acornui.core.i18n.Locale
import com.acornui.core.text.DateTimeFormatType
import com.acornui.core.text.DateTimeParser
import com.acornui.core.text.dateTimeFormatterProvider
import com.acornui.core.text.numberFormatterProvider
import com.acornui.core.time.time
import com.acornui.core.userInfo
import com.acornui.jvm.text.DateTimeFormatterImpl
import com.acornui.jvm.text.NumberFormatterImpl
import org.junit.Before
import org.junit.Test
import kotlin.test.assertEquals

class DateParserTest {

	@Before
	fun setUp() {
		val u = UserInfo(
				isDesktop = true,
				isTouchDevice = false,
				userAgent = "headless",
				platformStr = System.getProperty("os.name") ?: UserInfo.UNKNOWN_PLATFORM,
				systemLocale = listOf(Locale("en-US"))
		)
		userInfo = u
		time = TimeProviderImpl()
		numberFormatterProvider = { NumberFormatterImpl() }
		dateTimeFormatterProvider = { DateTimeFormatterImpl() }
	}

	@Test
	fun parseDate() {
		val parser = DateTimeParser()
		parser.type = DateTimeFormatType.DATE
		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048/3/11"))
		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048.3.11"))
		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048-3-11"))
		assertEquals(time.date(fullYear = 1950, month = 1, dayOfMonth = 1), parser.parse("1950/1/1"))
		assertEquals(time.date(fullYear = 1950, month = 1, dayOfMonth = 1), parser.parse("1950-1-1"))
		assertEquals(time.date(fullYear = 1950, month = 1, dayOfMonth = 1), parser.parse("1950-01-01"))
		assertEquals(null, parser.parse("3:33 2048/3/11"))
		assertEquals(null, parser.parse("T 2048/3/11"))
		assertEquals(null, parser.parse("19501/1/1"))
		assertEquals(null, parser.parse("1950/1.1"))
		assertEquals(null, parser.parse("1950/1-1"))
		assertEquals(null, parser.parse("195/1/1"))
		assertEquals(null, parser.parse("19/1/11000"))
		assertEquals(null, parser.parse("19/1/1"))
		assertEquals(null, parser.parse("1/1/1"))
		assertEquals(null, parser.parse("1/1"))
		assertEquals(time.date(fullYear = 1978, month = 12, dayOfMonth = 31), parser.parse("1978/12/31"))
		assertEquals(time.date(fullYear = 1978, month = 12, dayOfMonth = 31), parser.parse("12/31/1978"))

		parser.locales = listOf(Locale("de-DE"))
		assertEquals(time.date(fullYear = 1978, month = 12, dayOfMonth = 31), parser.parse("31/12/1978"))
	}

	@Test
	fun parseDateOptionalYear() {
		val currentYear = 2018
		val parser = DateTimeParser()
		parser.yearIsOptional = true
		parser.type = DateTimeFormatType.DATE

		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048/3/11"))
		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048.3.11"))
		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048-3-11"))
		assertEquals(time.date(fullYear = 1950, month = 1, dayOfMonth = 1), parser.parse("1950/1/1"))
		assertEquals(time.date(fullYear = 1950, month = 1, dayOfMonth = 1), parser.parse("1950-1-1"))
		assertEquals(time.date(fullYear = currentYear, month = 3, dayOfMonth = 11), parser.parse("3/11"))
		assertEquals(time.date(fullYear = currentYear, month = 3, dayOfMonth = 11), parser.parse("3.11"))
		assertEquals(time.date(fullYear = currentYear, month = 3, dayOfMonth = 11), parser.parse("3-11"))
		assertEquals(time.date(fullYear = currentYear, month = 1, dayOfMonth = 1), parser.parse("1/1"))
		assertEquals(time.date(fullYear = currentYear, month = 1, dayOfMonth = 1), parser.parse("1-1"))
		assertEquals(null, parser.parse("19501/1/1"))
		assertEquals(null, parser.parse("195/1/1"))
		assertEquals(null, parser.parse("19/1/11000"))
		assertEquals(null, parser.parse("19/1/1"))
		assertEquals(null, parser.parse("1/1/1"))
		assertEquals(time.date(fullYear = currentYear, month = 12, dayOfMonth = 31), parser.parse("12/31"))
		assertEquals(time.date(fullYear = currentYear, month = 12, dayOfMonth = 31), parser.parse("12/31"))
		assertEquals(null, parser.parse("13/6/2014"))
		assertEquals(null, parser.parse("-2/6/2014"))
		assertEquals(null, parser.parse("2/.6/2014"))<commit_msg>Date parser test set currentYear<commit_after>package com.acornui.jvm.time

import com.acornui.core.UserInfo
import com.acornui.core.i18n.Locale
import com.acornui.core.text.DateTimeFormatType
import com.acornui.core.text.DateTimeParser
import com.acornui.core.text.dateTimeFormatterProvider
import com.acornui.core.text.numberFormatterProvider
import com.acornui.core.time.time
import com.acornui.core.userInfo
import com.acornui.jvm.text.DateTimeFormatterImpl
import com.acornui.jvm.text.NumberFormatterImpl
import org.junit.Before
import org.junit.Test
import kotlin.test.assertEquals

class DateParserTest {

	@Before
	fun setUp() {
		val u = UserInfo(
				isDesktop = true,
				isTouchDevice = false,
				userAgent = "headless",
				platformStr = System.getProperty("os.name") ?: UserInfo.UNKNOWN_PLATFORM,
				systemLocale = listOf(Locale("en-US"))
		)
		userInfo = u
		time = TimeProviderImpl()
		numberFormatterProvider = { NumberFormatterImpl() }
		dateTimeFormatterProvider = { DateTimeFormatterImpl() }
	}

	@Test
	fun parseDate() {
		val parser = DateTimeParser()
		parser.type = DateTimeFormatType.DATE
		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048/3/11"))
		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048.3.11"))
		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048-3-11"))
		assertEquals(time.date(fullYear = 1950, month = 1, dayOfMonth = 1), parser.parse("1950/1/1"))
		assertEquals(time.date(fullYear = 1950, month = 1, dayOfMonth = 1), parser.parse("1950-1-1"))
		assertEquals(time.date(fullYear = 1950, month = 1, dayOfMonth = 1), parser.parse("1950-01-01"))
		assertEquals(null, parser.parse("3:33 2048/3/11"))
		assertEquals(null, parser.parse("T 2048/3/11"))
		assertEquals(null, parser.parse("19501/1/1"))
		assertEquals(null, parser.parse("1950/1.1"))
		assertEquals(null, parser.parse("1950/1-1"))
		assertEquals(null, parser.parse("195/1/1"))
		assertEquals(null, parser.parse("19/1/11000"))
		assertEquals(null, parser.parse("19/1/1"))
		assertEquals(null, parser.parse("1/1/1"))
		assertEquals(null, parser.parse("1/1"))
		assertEquals(time.date(fullYear = 1978, month = 12, dayOfMonth = 31), parser.parse("1978/12/31"))
		assertEquals(time.date(fullYear = 1978, month = 12, dayOfMonth = 31), parser.parse("12/31/1978"))

		parser.locales = listOf(Locale("de-DE"))
		assertEquals(time.date(fullYear = 1978, month = 12, dayOfMonth = 31), parser.parse("31/12/1978"))
	}

	@Test
	fun parseDateOptionalYear() {
		val currentYear = 2018
		val parser = DateTimeParser()
		parser.currentYear = currentYear
		parser.yearIsOptional = true
		parser.type = DateTimeFormatType.DATE

		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048/3/11"))
		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048.3.11"))
		assertEquals(time.date(fullYear = 2048, month = 3, dayOfMonth = 11), parser.parse("2048-3-11"))
		assertEquals(time.date(fullYear = 1950, month = 1, dayOfMonth = 1), parser.parse("1950/1/1"))
		assertEquals(time.date(fullYear = 1950, month = 1, dayOfMonth = 1), parser.parse("1950-1-1"))
		assertEquals(time.date(fullYear = currentYear, month = 3, dayOfMonth = 11), parser.parse("3/11"))
		assertEquals(time.date(fullYear = currentYear, month = 3, dayOfMonth = 11), parser.parse("3.11"))
		assertEquals(time.date(fullYear = currentYear, month = 3, dayOfMonth = 11), parser.parse("3-11"))
		assertEquals(time.date(fullYear = currentYear, month = 1, dayOfMonth = 1), parser.parse("1/1"))
		assertEquals(time.date(fullYear = currentYear, month = 1, dayOfMonth = 1), parser.parse("1-1"))
		assertEquals(null, parser.parse("19501/1/1"))
		assertEquals(null, parser.parse("195/1/1"))
		assertEquals(null, parser.parse("19/1/11000"))
		assertEquals(null, parser.parse("19/1/1"))
		assertEquals(null, parser.parse("1/1/1"))
		assertEquals(time.date(fullYear = currentYear, month = 12, dayOfMonth = 31), parser.parse("12/31"))
		assertEquals(time.date(fullYear = currentYear, month = 12, dayOfMonth = 31), parser.parse("12/31"))
		assertEquals(null, parser.parse("13/6/2014"))
		assertEquals(null, parser.parse("-2/6/2014"))
		assertEquals(null, parser.parse("2/.6/2014"))
{'fraction_non_alphanumeric': 0.16145710928319623, 'fraction_numerical': 0.08131609870740306, 'mean_word_length': 5.180827886710239, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '936530', 'n_tokens_mistral': 3420, 'n_tokens_neox': 2842, 'n_words': 531}