(self, value)
Parse a RFC 3339 date string format to Timestamp.

    Args:
      value: A date string. Any fractional digits (or none) and any offset are
          accepted as long as they fit into nano-seconds precision.
          Example of accepted format: '1972-01-01T10:00:20.021-05:00'

    Raises:
      ParseError: On parsing problems.
Parse a RFC 3339 date string format to Timestamp.
Parse a RFC 3339 date string format to Timestamp .
def FromJsonString(self, value):
    """Parse a RFC 3339 date string format to Timestamp.

    Args:
      value: A date string. Any fractional digits (or none) and any offset are
          accepted as long as they fit into nano-seconds precision.
          Example of accepted format: '1972-01-01T10:00:20.021-05:00'

    Raises:
      ParseError: On parsing problems.
    """
    timezone_offset = value.find('Z')
    if timezone_offset == -1:
      timezone_offset = value.find('+')
    if timezone_offset == -1:
      timezone_offset = value.rfind('-')
    if timezone_offset == -1:
      raise ParseError(
          'Failed to parse timestamp: missing valid timezone offset.')
    time_value = value[0:timezone_offset]
    # Parse datetime and nanos.
    point_position = time_value.find('.')
    if point_position == -1:
      second_value = time_value
      nano_value = ''
    else:
      second_value = time_value[:point_position]
      nano_value = time_value[point_position + 1:]
    date_object = datetime.strptime(second_value, _TIMESTAMPFOMAT)
    td = date_object - datetime(1970, 1, 1)
    seconds = td.seconds + td.days * _SECONDS_PER_DAY
    if len(nano_value) > 9:
      raise ParseError(
          'Failed to parse Timestamp: nanos {0} more than '
          '9 fractional digits.'.format(nano_value))
    if nano_value:
      nanos = round(float('0.' + nano_value) * 1e9)
    else:
      nanos = 0
    # Parse timezone offsets.
    if value[timezone_offset] == 'Z':
      if len(value) != timezone_offset + 1:
        raise ParseError('Failed to parse timestamp: invalid trailing'
                         ' data {0}.'.format(value))
    else:
      timezone = value[timezone_offset:]
      pos = timezone.find(':')
      if pos == -1:
        raise ParseError(
            'Invalid timezone offset value: {0}.'.format(timezone))
      if timezone[0] == '+':
        seconds -= (int(timezone[1:pos])*60+int(timezone[pos+1:]))*60
      else:
        seconds += (int(timezone[1:pos])*60+int(timezone[pos+1:]))*60
    # Set seconds and nanos
    self.seconds = int(seconds)
    self.nanos = int(nanos)
def FromJsonString ( self , value ) : timezone_offset = value . find ( 'Z' ) if timezone_offset == - 1 : timezone_offset = value . find ( '+' ) if timezone_offset == - 1 : timezone_offset = value . rfind ( '-' ) if timezone_offset == - 1 : raise ParseError ( 'Failed to parse timestamp: missing valid timezone offset.' ) time_value = value [ 0 : timezone_offset ] # Parse datetime and nanos. point_position = time_value . find ( '.' ) if point_position == - 1 : second_value = time_value nano_value = '' else : second_value = time_value [ : point_position ] nano_value = time_value [ point_position + 1 : ] date_object = datetime . strptime ( second_value , _TIMESTAMPFOMAT ) td = date_object - datetime ( 1970 , 1 , 1 ) seconds = td . seconds + td . days * _SECONDS_PER_DAY if len ( nano_value ) > 9 : raise ParseError ( 'Failed to parse Timestamp: nanos {0} more than ' '9 fractional digits.' . format ( nano_value ) ) if nano_value : nanos = round ( float ( '0.' + nano_value ) * 1e9 ) else : nanos = 0 # Parse timezone offsets. if value [ timezone_offset ] == 'Z' : if len ( value ) != timezone_offset + 1 : raise ParseError ( 'Failed to parse timestamp: invalid trailing' ' data {0}.' . format ( value ) ) else : timezone = value [ timezone_offset : ] pos = timezone . find ( ':' ) if pos == - 1 : raise ParseError ( 'Invalid timezone offset value: {0}.' . format ( timezone ) ) if timezone [ 0 ] == '+' : seconds -= ( int ( timezone [ 1 : pos ] ) * 60 + int ( timezone [ pos + 1 : ] ) ) * 60 else : seconds += ( int ( timezone [ 1 : pos ] ) * 60 + int ( timezone [ pos + 1 : ] ) ) * 60 # Set seconds and nanos self . seconds = int ( seconds ) self . nanos = int ( nanos )