<commit_before>﻿using System;

namespace AllReady.Providers
{
    public interface IDateTimeOffsetProvider
    {
        DateTimeOffset AdjustDateTimeOffsetTo(string timeZoneId, DateTimeOffset dateTimeOffset, int hour = 0, int minute = 0, int second = 0);
        DateTimeOffset AdjustDateTimeOffsetTo(TimeZoneInfo timeZoneInfo, DateTimeOffset dateTimeOffset, int hour = 0, int minute = 0, int second = 0);
        void AdjustDateTimeOffsetTo(string timeZoneId, DateTimeOffset startDateTimeOffset, DateTimeOffset endDateTimeOffset, out DateTimeOffset convertedStartDate, out DateTimeOffset convertedEndDate);
    }

    public class DateTimeOffsetProvider : IDateTimeOffsetProvider
    {
        public DateTimeOffset AdjustDateTimeOffsetTo(string timeZoneId, DateTimeOffset dateTimeOffset, int hour = 0, int minute = 0, int second = 0)
        {
            var timeZoneInfo = FindSystemTimeZoneBy(timeZoneId);
            return AdjustDateTimeOffsetTo(timeZoneInfo, dateTimeOffset, hour, minute, second);
        }

        public DateTimeOffset AdjustDateTimeOffsetTo(TimeZoneInfo timeZoneInfo, DateTimeOffset dateTimeOffset, int hour = 0, int minute = 0, int second = 0)
        {
            var timeSpan = timeZoneInfo.GetUtcOffset(dateTimeOffset);
            return new DateTimeOffset(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, hour, minute, second, timeSpan);
        }

        //only thing that sucks about this is we lose the ability to pass in the hour, minute and second optionally... if we did, the sig of this method would start to look pretty ugly
        //OR, we put the onus on the caller to make sure the correct hour/minute/second are attached to the start/endDateTimeOffset values provided to the method
        public void AdjustDateTimeOffsetTo(string timeZoneId, DateTimeOffset startDateTimeOffset, DateTimeOffset endDateTimeOffset, out DateTimeOffset convertedStartDate, out DateTimeOffset convertedEndDate)
        {
            var timeZoneInfo = FindSystemTimeZoneBy(timeZoneId);
            var timeSpan = timeZoneInfo.GetUtcOffset(startDateTimeOffset);
            convertedStartDate = new DateTimeOffset(startDateTimeOffset.Year, startDateTimeOffset.Month, startDateTimeOffset.Day, 0, 0, 0, timeSpan);
            convertedEndDate = new DateTimeOffset(endDateTimeOffset.Year, endDateTimeOffset.Month, endDateTimeOffset.Day, 0, 0, 0, timeSpan);
        }

        private static TimeZoneInfo FindSystemTimeZoneBy(string timeZoneId)
        {<commit_msg>Fixes incorrect AdjustDateTimeOffsetTo implemenation on DateTimeOffsetProvider<commit_after>﻿using System;

namespace AllReady.Providers
{
    public interface IDateTimeOffsetProvider
    {
        DateTimeOffset AdjustDateTimeOffsetTo(string timeZoneId, DateTimeOffset dateTimeOffset, int hour = 0, int minute = 0, int second = 0);
        DateTimeOffset AdjustDateTimeOffsetTo(TimeZoneInfo timeZoneInfo, DateTimeOffset dateTimeOffset, int hour = 0, int minute = 0, int second = 0);
        void AdjustDateTimeOffsetTo(string timeZoneId, DateTimeOffset startDateTimeOffset, DateTimeOffset endDateTimeOffset, out DateTimeOffset convertedStartDate, out DateTimeOffset convertedEndDate);
    }

    public class DateTimeOffsetProvider : IDateTimeOffsetProvider
    {
        public DateTimeOffset AdjustDateTimeOffsetTo(string timeZoneId, DateTimeOffset dateTimeOffset, int hour = 0, int minute = 0, int second = 0)
        {
            var timeZoneInfo = FindSystemTimeZoneBy(timeZoneId);
            return AdjustDateTimeOffsetTo(timeZoneInfo, dateTimeOffset, hour, minute, second);
        }

        public DateTimeOffset AdjustDateTimeOffsetTo(TimeZoneInfo timeZoneInfo, DateTimeOffset dateTimeOffset, int hour = 0, int minute = 0, int second = 0)
        {
            var timeSpan = timeZoneInfo.GetUtcOffset(dateTimeOffset);
            return new DateTimeOffset(dateTimeOffset.Year, dateTimeOffset.Month, dateTimeOffset.Day, hour, minute, second, timeSpan);
        }

        //only thing I don't like about this signature is we lose the ability to pass in the hour, minute and second optionally... if we did, the sig of this method would start to look pretty ugly
        //OR, we put the onus on the caller to make sure the correct hour/minute/second are attached to the start/endDateTimeOffset values provided to the method
        public void AdjustDateTimeOffsetTo(string timeZoneId, DateTimeOffset startDateTimeOffset, DateTimeOffset endDateTimeOffset, out DateTimeOffset convertedStartDate, out DateTimeOffset convertedEndDate)
        {
            var timeZoneInfo = FindSystemTimeZoneBy(timeZoneId);
            var startDateTimeSpan = timeZoneInfo.GetUtcOffset(startDateTimeOffset);
            var endDateTimeSpan = timeZoneInfo.GetUtcOffset(endDateTimeOffset);
            convertedStartDate = new DateTimeOffset(startDateTimeOffset.Year, startDateTimeOffset.Month, startDateTimeOffset.Day, 0, 0, 0, startDateTimeSpan);
            convertedEndDate = new DateTimeOffset(endDateTimeOffset.Year, endDateTimeOffset.Month, endDateTimeOffset.Day, 0, 0, 0, endDateTimeSpan);
        }

        private static TimeZoneInfo FindSystemTimeZoneBy(string timeZoneId)
        {
{'fraction_non_alphanumeric': 0.05778120184899846, 'fraction_numerical': 0.006933744221879815, 'mean_word_length': 4.0271055179090025, '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': '1693479', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1236, 'n_words': 418}