1
Vote

Problem with Database.cs

description

Issue in the LoadFile function in Database.cs .... ERROR message I get is :

DIED ON C:\temp\backzone row: Link Antarctica/McMurdo Antarctica/South_Pole ::: An item with the same key has already been added.

Anyone else getting this error ?

comments

dcernosia wrote Dec 4, 2014 at 2:15 AM

Ok .... downloaded your latest code, but now I get a compile error ....

in Rule.cs ... compile fails on this line
        // Parse the string
        string[] arr = line.Split(new [] {'\t', ' '}, StringSplitOptions.RemoveEmptyEntries);

dcernosia wrote Dec 4, 2014 at 2:43 AM

updated your code from :
string[] arr = line.Split(new [] {'\t', ' '}, StringSplitOptions.RemoveEmptyEntries);

to:
string[] arr = line.Split(new char [] {'\t', ' '}, StringSplitOptions.RemoveEmptyEntries);

this fixed the compile problem ... HOWEVER, still getting errors on backzone row: Zone Europe/Isle_of_Man -0:17:55 - LMT 1883 March 30 0:00s

ERROR : Input string was not in a correct format.

dcernosia wrote Dec 4, 2014 at 3:01 AM

Looks like there are too many TABS in the line for : Zone Europe/Isle_of_Man -0:17:55 - LMT 1883 March 30 0:00s

in Zone.cs, when it does the split on tabs, the array is 16 elements .... not the usual 10.

dcernosia wrote Dec 4, 2014 at 4:00 AM

And one more thing .... the month spelling changed in the source file ... "March" instead of "Mar", so it's throwing off the ConvertToMonth function in Database.cs

I added logging to your code ... I now get a ton of errors from these source files (all look to be new files except northamerica):

checktab.awk
CONTRIBUTING
NEWS
northamerica
Theory
zoneinfo2tdf.pl

dcernosia wrote Dec 4, 2014 at 9:19 PM

Hey ... I think I found the fixes needed to work with the current TimeZone data ... in case you want to include in your project :

+++++++++++++++++++++++++++++++++++++

FILE : ZONE.CS
FUNCTION : public static Zone Parse(string line, Zone defaultZone)
FIX : I think I found a way to remove all those additional NULL and EMPTY columns you get after splitting ... the comment marked MY FIX STARTS HERE
     // Create the zone we will be returning
        Zone zone = null;

        // Split up the line
        string[] arr = line.Split('\t', ' ');

        if (arr[0].Length > 0)
        {
            // MY FIX STARTS HERE
            if (arr.Length > 10)
            {
                string[] arrTemp = new string[20];
                int counter = 0;
                foreach (string elem in arr)
                {
                    if (elem != string.Empty)
                    {
                        arrTemp[counter] = elem;
                        counter++;
                    }
                }

                arr = new string[counter];

                counter = 0;
                foreach (string elem in arrTemp)
                {
                    if (elem != null && elem != string.Empty)
                    {
                        arr[counter] = elem;
                        counter++;
                    }
                }
            }
            // MY FIX ENDS HERE

            // The first token of the string is not empty.
            // Therefore it must be a new zone
            Debug.Assert(arr[0].StartsWith("Zone"), "Unexpected value when creating Zone", arr[0]);

            // Create a new zone
            zone = new Zone();
            zone.Name = arr[1];
        }
        else
        {
            // The first token of the string is empty
            // Therefore this is another rule of the last zone
            zone = defaultZone;
        }

+++++++++++++++++++++++++++++++++++++

FILE : DATABASE.CS
FUNCTION : public static int ConvertToMonth(string monthStr)
FIX : For one time zone, he specified the month as "March" instead of "Mar" ... updated the Month entries
            case "Mar":
                val = 3;
                break;
            case "March":
                val = 3;
                break;
+++++++++++++++++++++++++++++++++++++

FILE : DATABASE.CS
FUNCTION : public static void LoadFiles(string directory)
FIX : Filtered out the new files that broke the code
    public static void LoadFiles(string directory)
    {
        string[] files = Directory.GetFiles(directory);

        foreach (string file in files)
        {
            // Ignore the .tab and .sh files
            // Also the factory and leapsecond files
            // This is pretty crude but does the job
            if (file.EndsWith(".tab") || file.EndsWith(".sh")
                || file.EndsWith("\\factory") || file.EndsWith("\\leapseconds") || file.EndsWith("\\leapseconds.awk")
                || file.EndsWith("\\leap-seconds.list") || file.EndsWith("\\Makefile") || file.EndsWith("\\README")
                || file.EndsWith("\\checktab.awk") || file.EndsWith("\\CONTRIBUTING") || file.EndsWith("\\NEWS")
                || file.EndsWith("\\Theory") || file.EndsWith("\\zoneinfo2tdf.pl")
                )
            {
                continue;
            }

            // Now load each of the files
            LoadFile(file);
        }
    }
+++++++++++++++++++++++++++++++++++++

FILE :RULE.CS
FUNCTION : public Rule(string line)
FIX : Would not compile ... needed "char" as a type
        //string[] arr = line.Split(new [] {'\t', ' '}, StringSplitOptions.RemoveEmptyEntries);
        string[] arr = line.Split(new char[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);