Esempio n. 1
0
    private void ParseMeridianAndSetHour( ClockToken[] dt, ref System.Int32 parsePos, TclDateTime calendar, int hour )
    // hour value (1-12 or 0-23) to set.
    {
      int pos = parsePos;
      int hourField;

      if ( pos < dt.Length && dt[pos].is_Renamed( ClockToken.MERIDIAN ) )
      {
        // SupportClass.CalendarManager.manager.Set(calendar, SupportClass.CalendarManager.AM_PM, dt[pos].Int);
        parsePos = pos + 1;
        hourField = SupportClass.CalendarManager.HOUR;
      }
      else
      {
        hourField = SupportClass.CalendarManager.HOUR_OF_DAY;
      }

      if ( hourField == SupportClass.CalendarManager.HOUR && hour == 12 )
      {
        hour = 0;
      }
      calendar.hour = hour;
    }
Esempio n. 2
0
    private bool ParseIso( ClockToken[] dt, ref System.Int32 parsePos, TclDateTime calendar )
    // calendar object to set
    {
      int pos = parsePos;

      if ( pos + 6 < dt.Length && dt[pos].IsoBase && dt[pos + 1].is_Renamed( ClockToken.ZONE ) && dt[pos + 2].UNumber && dt[pos + 3].is_Renamed( ':' ) && dt[pos + 4].UNumber && dt[pos + 5].is_Renamed( ':' ) && dt[pos + 6].UNumber )
      {
        calendar.day = dt[pos].Int % 100;
        calendar.month = ( dt[pos].Int % 10000 ) / 100;
        calendar.year = dt[pos].Int / 10000;
        calendar.hour = dt[pos + 2].Int;
        calendar.minute = dt[pos + 4].Int;
        calendar.second = dt[pos + 6].Int;
        parsePos = pos + 7;
        return true;
      }
      if ( pos + 2 < dt.Length && dt[pos].IsoBase && dt[pos + 1].is_Renamed( ClockToken.ZONE ) && dt[pos + 1].Zone.GetUtcOffset( calendar.dateTime ).Hours == ( -7 ) * MILLIS_PER_HOUR && dt[pos + 2].IsoBase )
      {
        calendar.day = dt[pos].Int % 100;
        calendar.month = ( dt[pos].Int % 10000 ) / 100;
        calendar.year = dt[pos].Int / 10000;
        calendar.hour = dt[pos + 2].Int / 10000;
        calendar.minute = ( dt[pos + 2].Int % 10000 ) / 100;
        calendar.second = dt[pos + 2].Int % 100;
        parsePos = pos + 3;
        return true;
      }
      if ( pos + 1 < dt.Length && dt[pos].IsoBase && dt[pos + 1].IsoBase )
      {
        calendar.day = dt[pos].Int % 100;
        calendar.month = ( dt[pos].Int % 10000 ) / 100;
        calendar.year = dt[pos].Int / 10000;
        calendar.hour = dt[pos + 1].Int / 10000;
        calendar.minute = ( dt[pos + 1].Int % 10000 ) / 100;
        calendar.second = dt[pos + 1].Int % 100;
        parsePos = pos + 2;
        return true;
      }
      return false;
    }
Esempio n. 3
0
    private bool ParseTrek( ClockToken[] dt, ref System.Int32 parsePos, TclDateTime calendar )
    // calendar object to set
    {
      int pos = parsePos;

      if ( pos + 3 < dt.Length && dt[pos].is_Renamed( ClockToken.STARDATE ) && dt[pos + 1].UNumber && dt[pos + 2].is_Renamed( '.' ) && dt[pos + 3].UNumber )
      {
        GregorianCalendar gcal = new GregorianCalendar();
        int trekYear = dt[pos + 1].Int / 1000 + 2323 - 377;
        int trekDay = 1 + ( ( dt[pos + 1].Int % 1000 ) * ( gcal.IsLeapYear( trekYear ) ? 366 : 365 ) ) / 1000;
        int trekSeconds = dt[pos + 3].Int * 144 * 60;
        calendar.year = trekYear;
        calendar.dateTime = gcal.AddDays( calendar.dateTime, trekDay );
        calendar.second = trekSeconds;
        parsePos = pos + 4;
        return true;
      }
      return false;
    }
Esempio n. 4
0
    private bool ParseRelUnits( ClockToken[] dt, ref System.Int32 parsePos, ClockRelTimespan diff )
    // time difference to evaluate
    {
      int pos = parsePos;

      if ( pos + 2 < dt.Length && dt[pos].is_Renamed( '+' ) && dt[pos + 1].UNumber && dt[pos + 2].Unit )
      {
        diff.addUnit( dt[pos + 2], dt[pos + 1].Int );
        parsePos = pos + 3;
        return true;
      }
      if ( pos + 2 < dt.Length && dt[pos].is_Renamed( '-' ) && dt[pos + 1].UNumber && dt[pos + 2].Unit )
      {
        diff.addUnit( dt[pos + 2], -dt[pos + 1].Int );
        parsePos = pos + 3;
        return true;
      }
      if ( pos + 1 < dt.Length && dt[pos].UNumber && dt[pos + 1].Unit )
      {
        diff.addUnit( dt[pos + 1], dt[pos].Int );
        parsePos = pos + 2;
        return true;
      }
      else if ( pos + 2 < dt.Length && dt[pos].is_Renamed( ClockToken.NEXT ) && dt[pos + 1].UNumber && dt[pos + 2].Unit )
      {
        diff.addUnit( dt[pos + 2], dt[pos + 1].Int );
        parsePos = pos + 3;
        return true;
      }
      if ( pos + 1 < dt.Length && dt[pos].is_Renamed( ClockToken.NEXT ) && dt[pos + 1].Unit )
      {
        diff.addUnit( dt[pos + 1] );
        parsePos = pos + 2;
        return true;
      }
      if ( pos < dt.Length && dt[pos].Unit )
      {
        diff.addUnit( dt[pos] );
        parsePos = pos + 1;
        return true;
      }
      return false;
    }
Esempio n. 5
0
    private bool ParseOrdMonth( ClockToken[] dt, ref System.Int32 parsePos, ClockRelTimespan diff )
    // time difference to evaluate
    {
      int pos = parsePos;

      if ( pos + 2 < dt.Length && dt[pos].is_Renamed( ClockToken.NEXT ) && dt[pos + 1].UNumber && dt[pos + 2].is_Renamed( ClockToken.MONTH ) )
      {
        diff.addOrdMonth( dt[pos + 2].Int, dt[pos + 1].Int );
        parsePos = pos + 3;
        return true;
      }
      if ( pos + 1 < dt.Length && dt[pos].is_Renamed( ClockToken.NEXT ) && dt[pos + 1].is_Renamed( ClockToken.MONTH ) )
      {
        diff.addOrdMonth( dt[pos + 1].Int, 1 );
        parsePos = pos + 2;
        return true;
      }
      return false;
    }
Esempio n. 6
0
    private bool ParseNumber( ClockToken[] dt, ref System.Int32 parsePos, TclDateTime calendar, bool mayBeYear )
    // number is considered to be year?
    {
      int pos = parsePos;

      if ( pos < dt.Length && dt[pos].UNumber )
      {
        parsePos = pos + 1;
        if ( mayBeYear )
        {
          calendar.year = dt[pos].Int;
        }
        else
        {
          calendar.hour = dt[pos].Int / 100;
          calendar.minute = dt[pos].Int % 100;
          calendar.second = 0;
        }
        return true;
      }
      return false;
    }
Esempio n. 7
0
    private bool ParseRelSpec( ClockToken[] dt, ref System.Int32 parsePos, ClockRelTimespan diff )
    // time difference to evaluate
    {
      if ( !ParseRelUnits( dt, ref parsePos, diff ) )
      {
        return false;
      }

      int pos = parsePos;
      if ( pos < dt.Length && dt[pos].is_Renamed( ClockToken.AGO ) )
      {
        diff.negate();
        parsePos = pos + 1;
      }
      return true;
    }
Esempio n. 8
0
    private bool ParseDay( ClockToken[] dt, ref System.Int32 parsePos, ClockRelTimespan diff )
    // time difference to evaluate
    {
      int pos = parsePos;

      if ( pos + 2 < dt.Length && dt[pos].is_Renamed( '+' ) && dt[pos + 1].UNumber && dt[pos + 2].is_Renamed( ClockToken.DAY ) )
      {
        diff.setWeekday( dt[pos + 2].Int, dt[pos + 1].Int );
        parsePos = pos + 3;
        return true;
      }
      if ( pos + 2 < dt.Length && dt[pos].is_Renamed( '-' ) && dt[pos + 1].UNumber && dt[pos + 2].is_Renamed( ClockToken.DAY ) )
      {
        diff.setWeekday( dt[pos + 2].Int, -dt[pos + 1].Int );
        parsePos = pos + 3;
        return true;
      }
      if ( pos + 1 < dt.Length && dt[pos].is_Renamed( ClockToken.NEXT ) && dt[pos + 1].is_Renamed( ClockToken.DAY ) )
      {
        diff.setWeekday( dt[pos + 1].Int, 2 );
        parsePos = pos + 2;
        return true;
      }
      if ( pos + 1 < dt.Length && dt[pos].is_Renamed( ClockToken.DAY ) && dt[pos + 1].is_Renamed( ',' ) )
      {
        diff.setWeekday( dt[pos].Int );
        parsePos = pos + 2;
        return true;
      }
      if ( pos + 1 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( ClockToken.DAY ) )
      {
        diff.setWeekday( dt[pos + 1].Int, dt[pos].Int );
        parsePos = pos + 2;
        return true;
      }
      if ( pos < dt.Length && dt[pos].is_Renamed( ClockToken.DAY ) )
      {
        diff.setWeekday( dt[pos].Int );
        parsePos = pos + 1;
        return true;
      }
      return false;
    }
Esempio n. 9
0
    private bool ParseDate( ClockToken[] dt, ref System.Int32 parsePos, TclDateTime calendar )
    // calendar object to set
    {
      int pos = parsePos;

      if ( pos + 4 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( '/' ) && dt[pos + 2].UNumber && dt[pos + 3].is_Renamed( '/' ) && dt[pos + 4].UNumber )
      {
        calendar.day = dt[pos + 2].Int;
        calendar.month = dt[pos].Int;
        calendar.year = dt[pos + 4].Int;
        parsePos = pos + 5;
        return true;
      }
      if ( pos + 4 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( '-' ) && dt[pos + 2].is_Renamed( ClockToken.MONTH ) && dt[pos + 3].is_Renamed( '-' ) && dt[pos + 4].UNumber )
      {
        calendar.year = dt[pos + 4].Int;
        calendar.month = dt[pos + 2].Int;
        calendar.day = dt[pos].Int;
        parsePos = pos + 5;
        return true;
      }
      if ( pos + 4 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( '-' ) && dt[pos + 2].UNumber && dt[pos + 3].is_Renamed( '-' ) && dt[pos + 4].UNumber )
      {
        calendar.year = dt[pos].Int;
        calendar.month = dt[pos + 2].Int;
        calendar.day = dt[pos + 4].Int;
        parsePos = pos + 5;
        return true;
      }
      if ( pos + 3 < dt.Length && dt[pos].is_Renamed( ClockToken.MONTH ) && dt[pos + 1].UNumber && dt[pos + 2].is_Renamed( ',' ) && dt[pos + 3].UNumber )
      {
        calendar.day = dt[pos + 1].Int;
        calendar.month = dt[pos].Int;
        calendar.year = dt[pos + 3].Int;
        parsePos = pos + 4;
        return true;
      }
      if ( pos + 2 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( '/' ) && dt[pos + 2].UNumber )
      {
        calendar.day = dt[pos + 2].Int;
        calendar.month = dt[pos].Int;
        parsePos = pos + 3;
        return true;
      }
      if ( pos + 2 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( ClockToken.MONTH ) && dt[pos + 2].UNumber )
      {
        calendar.day = dt[pos].Int;
        calendar.month = dt[pos + 1].Int;
        calendar.year = dt[pos + 2].Int;
        parsePos = pos + 3;
        return true;
      }
      if ( pos + 1 < dt.Length && dt[pos].is_Renamed( ClockToken.MONTH ) && dt[pos + 1].UNumber )
      {
        calendar.day = dt[pos + 1].Int;
        calendar.month = dt[pos].Int;
        parsePos = pos + 2;
        return true;
      }
      if ( pos + 1 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( ClockToken.MONTH ) )
      {
        calendar.day = dt[pos].Int;
        calendar.month = dt[pos + 1].Int;
        parsePos = pos + 2;
        return true;
      }
      if ( pos < dt.Length && dt[pos].IsoBase )
      {
        calendar.day = dt[pos].Int % 100;
        calendar.month = ( dt[pos].Int % 10000 ) / 100;
        calendar.year = dt[pos].Int / 10000;
        parsePos = pos + 1;
        return true;
      }
      if ( pos < dt.Length && dt[pos].is_Renamed( ClockToken.EPOCH ) )
      {
        calendar.day = 1;
        calendar.month = 0;
        calendar.year = EPOCH_YEAR;
        parsePos = pos + 1;
        return true;
      }
      return false;
    }
Esempio n. 10
0
    private bool ParseZone( ClockToken[] dt, ref System.Int32 parsePos, TclDateTime calendar )
    // calendar object to set
    {
      int pos = parsePos;

      if ( pos + 1 < dt.Length && dt[pos].is_Renamed( ClockToken.ZONE ) && dt[pos + 1].is_Renamed( ClockToken.DST ) )
      {

        //				calendar.setTimeZone(dt[pos].Zone);
        parsePos = pos + 2;
        return true;
      }
      if ( pos < dt.Length && dt[pos].is_Renamed( ClockToken.ZONE ) )
      {

        //				calendar.setTimeZone(dt[pos].Zone);
        parsePos = pos + 1;
        return true;
      }
      if ( pos < dt.Length && dt[pos].is_Renamed( ClockToken.DAYZONE ) )
      {

        //				calendar.setTimeZone(dt[pos].Zone);
        parsePos = pos + 1;
        return true;
      }
      return false;
    }
Esempio n. 11
0
    private bool ParseTime( ClockToken[] dt, ref System.Int32 parsePos, TclDateTime calendar )
    // calendar object to set
    {
      int pos = parsePos;

      if ( pos + 6 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( ':' ) && dt[pos + 2].UNumber && dt[pos + 3].is_Renamed( ':' ) && dt[pos + 4].UNumber && dt[pos + 5].is_Renamed( '-' ) && dt[pos + 6].UNumber )
      {
        ClockToken zone = GetTimeZoneFromRawOffset( ( -dt[pos + 6].Int ) / 100 );
        if ( zone != null )
        {
          calendar.hour = dt[pos].Int;
          calendar.minute = dt[pos + 2].Int;
          calendar.second = dt[pos + 4].Int;
          // TODO
          //					calendar.setTimeZone(zone.Zone);
          parsePos = pos + 7;
          return true;
        }
      }
      if ( pos + 4 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( ':' ) && dt[pos + 2].UNumber && dt[pos + 3].is_Renamed( ':' ) && dt[pos + 4].UNumber )
      {
        parsePos = pos + 5;
        ParseMeridianAndSetHour( dt, ref parsePos, calendar, dt[pos].Int );
        calendar.minute = dt[pos + 2].Int;
        calendar.second = dt[pos + 4].Int;
        return true;
      }
      if ( pos + 4 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( ':' ) && dt[pos + 2].UNumber && dt[pos + 3].is_Renamed( '-' ) && dt[pos + 4].UNumber )
      {
        ClockToken zone = GetTimeZoneFromRawOffset( ( -dt[pos + 4].Int ) / 100 );
        if ( zone != null )
        {
          calendar.hour = dt[pos].Int;
          calendar.minute = dt[pos + 2].Int;

          //					calendar.setTimeZone(zone.Zone);
          parsePos = pos + 5;
          return true;
        }
      }
      if ( pos + 2 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( ':' ) && dt[pos + 2].UNumber )
      {
        parsePos = pos + 3;
        ParseMeridianAndSetHour( dt, ref parsePos, calendar, dt[pos].Int );
        calendar.minute = dt[pos + 2].Int;
        return true;
      }
      if ( pos + 1 < dt.Length && dt[pos].UNumber && dt[pos + 1].is_Renamed( ClockToken.MERIDIAN ) )
      {
        parsePos = pos + 1;
        ParseMeridianAndSetHour( dt, ref parsePos, calendar, dt[pos].Int );
        return true;
      }
      return false;
    }
Esempio n. 12
0
 internal void addUnit( ClockToken unit )
 {
   addUnit( unit, 1 );
 }
Esempio n. 13
0
 internal void addUnit( ClockToken unit, int amount )
 {
   if ( unit.is_Renamed( ClockToken.SEC_UNIT ) )
   {
     addSeconds( unit.Int * amount );
   }
   else if ( unit.is_Renamed( ClockToken.MINUTE_UNIT ) )
   {
     addSeconds( unit.Int * 60 * amount );
   }
   else if ( unit.is_Renamed( ClockToken.MONTH_UNIT ) )
   {
     addMonths( unit.Int * amount );
   }
 }
Esempio n. 14
0
    private ClockToken[] GetTokens( string in_Renamed, bool debug )
    // Send the generated token list to stderr?
    {
      System.Int32 parsePos = 0;
      ClockToken dt;
      ArrayList tokenVector = new ArrayList( in_Renamed.Length );

      while ( ( dt = GetNextToken( in_Renamed, ref parsePos ) ) != null )
      {
        tokenVector.Add( dt );
      }

      ClockToken[] tokenArray = new ClockToken[tokenVector.Count];
      tokenVector.CopyTo( tokenArray );

#if DEBUG
      for ( int ix = 0; ix < tokenArray.Length; ix++ )
      {
        if ( ix != 0 )
        {
          System.Console.Error.Write( "," );
        }

        System.Console.Error.Write( tokenArray[ix].ToString() );
      }
      System.Console.Error.WriteLine( "" );
#endif

      return tokenArray;
    }