<commit_before>﻿using System;
using System.Collections.Generic;

namespace MovieMiner
{
	public static class MovieDateUtil
	{
		// This offset may change depending on what year we're in (or the whims of FML)
		private const int SEASON_OFFSET_WEEKS = 8;
		private const int DAYS_IN_WEEK = 7;
		private const int WEEKS_IN_SEASON = 13;

		private static readonly List<string> _seasons = new List<string> { "Spring", "Summer", "Fall", "Winter" };

		/// <summary>
		/// The first Sunday (weekend ending) of the spring season.
		/// </summary>
		public static DateTime StartOfSeason => NextSunday(new DateTime(DateTime.Now.Year, 1, 1)).AddDays(7 * SEASON_OFFSET_WEEKS);

		public static string DateToSeason(DateTime? dateTime = null)
		{
			DateTime reference = dateTime ?? Now;
			var diff = reference.Subtract(StartOfSeason);
			var index = diff.Days / (DAYS_IN_WEEK * WEEKS_IN_SEASON);
			string result = null;

			if (index < _seasons.Count)
			{
				result = _seasons[index];
			}

			return result;
		}

		public static int DateToWeek(DateTime? dateTime = null)
		{
			DateTime reference = dateTime ?? NextSunday();

			var diff = reference.Subtract(StartOfSeason);
			return (diff.Days / DAYS_IN_WEEK) % WEEKS_IN_SEASON + 1;
		}

		public static DateTime GameSunday(DateTime? dateTime = null, bool isEstimate = false)
		{
			DateTime result = dateTime ?? Now;

			if (result.DayOfWeek == DayOfWeek.Monday && isEstimate)
			{
				result = result.AddDays(-1);
			}
			else
			{
				result = ThisSunday(result);
			}

			return result;
		}

		public static DateTime LastSunday(DateTime? dateTime = null)
		{
			DateTime reference = dateTime ?? Now;

			return reference.AddDays(DayOfWeek.Sunday - reference.DayOfWeek);
		}

		public static DateTime NextSunday(DateTime? dateTime = null)
		{
			DateTime reference = dateTime ?? Now;

			return reference.AddDays(7 - (int)reference.DayOfWeek);
		}

		public static DateTime ThisSunday(DateTime? dateTime = null)
		{
			DateTime result = dateTime ?? Now;

			if (result.DayOfWeek != DayOfWeek.Sunday)
			{
				// Sunday = 0 --> Saturday = 6
				result = result.AddDays(7 - (int)result.DayOfWeek);
			}

			return result;
		}

		private static DateTime Now => DateTime.Now.Date;
	}
}<commit_msg>Adding some game time methods.<commit_after>﻿using System;
using System.Collections.Generic;

namespace MovieMiner
{
	public static class MovieDateUtil
	{
		private const int TZ_OFFSET = -7;        // The mountain time zone is 7 hours behind UTC.

		// This offset may change depending on what year we're in (or the whims of FML)
		private const int SEASON_OFFSET_WEEKS = 8;
		private const int DAYS_IN_WEEK = 7;
		private const int WEEKS_IN_SEASON = 13;

		private static readonly List<string> _seasons = new List<string> { "Spring", "Summer", "Fall", "Winter" };

		/// <summary>
		/// The first Sunday (weekend ending) of the spring season.
		/// </summary>
		public static DateTime StartOfSeason => NextSunday(new DateTime(DateTime.Now.Year, 1, 1)).AddDays(7 * SEASON_OFFSET_WEEKS);

		public static string DateToSeason(DateTime? dateTime = null)
		{
			DateTime reference = dateTime ?? Now;
			var diff = reference.Subtract(StartOfSeason);
			var index = diff.Days / (DAYS_IN_WEEK * WEEKS_IN_SEASON);
			string result = null;

			if (index < _seasons.Count)
			{
				result = _seasons[index];
			}

			return result;
		}

		public static int DateToWeek(DateTime? dateTime = null)
		{
			DateTime reference = dateTime ?? NextSunday();

			var diff = reference.Subtract(StartOfSeason);
			return (diff.Days / DAYS_IN_WEEK) % WEEKS_IN_SEASON + 1;
		}

		public static DateTime GameSunday(DateTime? dateTime = null, bool isEstimate = false)
		{
			DateTime result = dateTime ?? Now;

			if (result.DayOfWeek == DayOfWeek.Monday && isEstimate)
			{
				result = result.AddDays(-1);
			}
			else
			{
				result = ThisSunday(result);
			}

			return result;
		}

		public static DateTime LastSunday(DateTime? dateTime = null)
		{
			DateTime reference = dateTime ?? Now;

			return reference.AddDays(DayOfWeek.Sunday - reference.DayOfWeek);
		}

		public static DateTime NextSunday(DateTime? dateTime = null)
		{
			DateTime reference = dateTime ?? Now;

			return reference.AddDays(7 - (int)reference.DayOfWeek);
		}

		public static DateTime ThisSunday(DateTime? dateTime = null)
		{
			DateTime result = dateTime ?? Now;

			if (result.DayOfWeek != DayOfWeek.Sunday)
			{
				// Sunday = 0 --> Saturday = 6
				result = result.AddDays(7 - (int)result.DayOfWeek);
			}

			return result;
		}

		public static TimeSpan UntilGameTime()
		{
			// The mountain time zone is 7 hours behind UTC.

			var now = DateTime.Now;
			var start = GameStartTime();
			var end = GameEndTime();
			TimeSpan result = new TimeSpan(0);
		
			if (start < end)
			{
				result = start.Subtract(now);
			}

			return new TimeSpan();
		}

		/// <summary>
		/// Always moving forward from Now
		/// </summary>
		/// <returns>Game start time within the time zone</returns>
		public static DateTime GameEndTime()
		{
			var now = Now;
			var result = new DateTime(now.Year, now.Month, now.Day + (DayOfWeek.Tuesday - now.DayOfWeek), now.Hour, now.Minute, now.Second);

			if (DayOfWeek.Friday - now.DayOfWeek < 0)
			{
				// Went backwards to Tuesday so add a whole week.

				result.AddDays(7);
			}

			return result;
		}

		/// <summary>
		/// Always moving forward from Now
		/// </summary>
		/// <returns>Game start time within the time zone</returns>
		public static DateTime GameStartTime()
		{
			var now = Now;
			var result = new DateTime(now.Year, now.Month, now.Day + (DayOfWeek.Friday - now.DayOfWeek), now.Hour, now.Minute, now.Second);

			if (DayOfWeek.Friday - now.DayOfWeek < 0)
			{
				// Went backwards to Friday so add a whole week.

				result.AddDays(7);
			}

			return result;
		}

		private static DateTime Now => DateTime.Now.AddHours(TZ_OFFSET).Date;
	}
}
{'fraction_non_alphanumeric': 0.11207188877585622, 'fraction_numerical': 0.005764665988470668, 'mean_word_length': 3.1896306818181817, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 25, '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': '5801843', 'n_tokens_mistral': 2296, 'n_tokens_neox': 1861, 'n_words': 536}