src/sys/dotnet/fan/sys/TimeZone.cs
/// <summary>
/// Find the specified name in the index and load a time zone
/// definition.  If the name is not found then return null.
/// </summary>
Find the specified name in the index and load a time zone
definition.  If the name is not found then return null.
Find the specified name in the index and load a time zone definition . If the name is not found then return null .
static TimeZone loadTimeZone(string x)
    {
      string name = x;
      int slash = x.LastIndexOf('/');
      if (slash > 0) name = name.Substring(slash+1);
      int ix = -1;
      for (int i=0; i<indexNames.Length; ++i)
        if (name == indexNames[i]) { ix = i; break; }
      if (ix < 0) return null;
      string fullName = name;
      string prefix = prefixes[indexPrefixes[ix] & 0xff];
      if (prefix.Length != 0) fullName = prefix + "/" + name;
      if (slash > 0 && x != fullName) return null;
      TimeZone tz = new TimeZone();
      tz.m_name      = name;
      tz.m_fullName  = fullName;
      FileStream f = dbFile.OpenRead();
      DataReader d = new DataReader(f);
      try
      {
        f.Seek(indexOffsets[ix], SeekOrigin.Begin);
        int numRules  = d.ReadUnsignedShort();
        tz.rules = new Rule[numRules];
        for (int i=0; i<numRules; ++i)
        {
          Rule r = tz.rules[i] = new Rule();
          r.startYear = d.ReadUnsignedShort();
          r.offset    = d.ReadInt();
          r.stdAbbr   = d.ReadUTF();
          r.dstOffset = d.ReadInt();
          if (r.dstOffset == 0) continue;
          r.dstAbbr   = d.ReadUTF();
          r.dstStart  = loadDstTime(d);
          r.dstEnd    = loadDstTime(d);
          if (i != 0 && tz.rules[i-1].startYear <= r.startYear)
            throw new IOException("TimeZone rules not sorted: " + name);
        }
      }
      finally
      {
        f.Close();
      }
      return tz;
    }
static TimeZone loadTimeZone ( string x ) { string name = x ; int slash = x . LastIndexOf ( ' ' ) ; if ( slash > 0 ) name = name . Substring ( slash + 1 ) ; int ix = - 1 ; for ( int i = 0 ; i < indexNames . Length ; ++ i ) if ( name == indexNames [ i ] ) { ix = i ; break ; } if ( ix < 0 ) return null ; string fullName = name ; string prefix = prefixes [ indexPrefixes [ ix ] & 0xff ] ; if ( prefix . Length != 0 ) fullName = prefix + " " + name ; if ( slash > 0 && x != fullName ) return null ; TimeZone tz = new TimeZone ( ) ; tz . m_name = name ; tz . m_fullName = fullName ; FileStream f = dbFile . OpenRead ( ) ; DataReader d = new DataReader ( f ) ; try { f . Seek ( indexOffsets [ ix ] , SeekOrigin . Begin ) ; int numRules = d . ReadUnsignedShort ( ) ; tz . rules = new Rule [ numRules ] ; for ( int i = 0 ; i < numRules ; ++ i ) { Rule r = tz . rules [ i ] = new Rule ( ) ; r . startYear = d . ReadUnsignedShort ( ) ; r . offset = d . ReadInt ( ) ; r . stdAbbr = d . ReadUTF ( ) ; r . dstOffset = d . ReadInt ( ) ; if ( r . dstOffset == 0 ) continue ; r . dstAbbr = d . ReadUTF ( ) ; r . dstStart = loadDstTime ( d ) ; r . dstEnd = loadDstTime ( d ) ; if ( i != 0 && tz . rules [ i - 1 ] . startYear <= r . startYear ) throw new IOException ( " " + name ) ; } } finally { f . Close ( ) ; } return tz ; }
Find the specified name in the index and load a time zone
definition.
Find the specified name in the index and load a time zone definition .
// find index, which maps the file offset // TODO: why doesn't BinarySearch work? // int ix = Array.BinarySearch(indexNames, name); // map full name // create time zone instance // read time zone definition from database file
x
string