0

Hi I am trying to make a request to the Google Calendar API V3 and setting a minDate value. According to the Google API documentation the date needs to be encoded. see: https://developers.google.com/google-apps/calendar/v3/reference/events/list

Looking at the explanations given in this Question: Swift - encode URL I can party achieve this by using the following:

// todayString = "2014-11-10T23:15:25+1300"
var escapedTodayString:NSString! = todayString.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet())

This however only encodes part of the string and the output is: 2014-11-10T23%3A15%3A25+1300 This fails in the request. The output I require is: 2014-11-10T22%3A38%3A48%2B1300

When I make the request using the desired output it works as expected.

How can I achieve this level of encoding please?

Community
  • 1
  • 1
TResponse
  • 3,940
  • 7
  • 43
  • 63

1 Answers1

0

You can achieve that by following code. Which removes "+" from the allowed characters

var todayString = "2014-11-10T23:15:25+1300"

var characters = NSCharacterSet.URLHostAllowedCharacterSet().mutableCopy() as NSMutableCharacterSet

characters.removeCharactersInString("+")

var escapedTodayString:NSString! = todayString.stringByAddingPercentEncodingWithAllowedCharacters(characters)
Shuo
  • 8,447
  • 4
  • 30
  • 36
  • Great help Shuo thanks! I also had to add the characters.removeCharactersInString(":") to get rid of the colons. – TResponse Nov 10 '14 at 23:13