Sha256: 0a415f9213523b32c362804c6568876fbb3b4df6c22225f0702de2a4d048ce69

Contents?: true

Size: 1.23 KB

Versions: 86

Compression:

Stored size: 1.23 KB

Contents

using System;
using System.Collections.Generic;
using Generators.Input;
using Generators.Output;

namespace Generators.Exercises
{
    public class Gigasecond : GeneratorExercise
    {
        protected override void UpdateCanonicalData(CanonicalData canonicalData)
        {
            foreach (var canonicalDataCase in canonicalData.Cases)
            {
                var input = DateTime.Parse(canonicalDataCase.Properties["input"].ToString());
                canonicalDataCase.Properties["input"] = new UnescapedValue(FormatDateTime(input));
                
                canonicalDataCase.Expected = new UnescapedValue(FormatDateTime((DateTime)canonicalDataCase.Expected));                
            }
        }

        protected override HashSet<string> AddAdditionalNamespaces() => new HashSet<string> { typeof(DateTime).Namespace };

        private static string FormatDateTime(DateTime dateTime)
        {
            return dateTime.Hour == 0 && dateTime.Minute == 0 && dateTime.Second == 0
                ? $"new DateTime({dateTime.Year}, {dateTime.Month}, {dateTime.Day})"
                : $"new DateTime({dateTime.Year}, {dateTime.Month}, {dateTime.Day}, {dateTime.Hour}, {dateTime.Minute}, {dateTime.Second})";
        }
    }
}

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
trackler-2.2.1.151 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.150 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.149 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.148 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.147 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.146 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.145 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.144 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.143 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.142 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.141 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.140 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.139 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.138 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.137 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.136 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.135 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.134 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.133 tracks/csharp/generators/Exercises/Gigasecond.cs
trackler-2.2.1.132 tracks/csharp/generators/Exercises/Gigasecond.cs