Skip to content

Commit

Permalink
Use NSDateFormatter on all iOS versions to keep the code simple
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanregisser committed Oct 25, 2018
1 parent b8d8065 commit e039423
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions ios/RCPurchaserInfo+RNPurchases.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@

#import "RCPurchaserInfo+RNPurchases.h"

static id formatter;
static NSDateFormatter *formatter;
static dispatch_once_t onceToken;

static NSString * stringFromDate(NSDate *date)
{
dispatch_once(&onceToken, ^{
if (@available(iOS 10.0, *)) {
formatter = [NSISO8601DateFormatter new];
} else {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'";
dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
formatter = dateFormatter;
}
// Here we're not using NSISO8601DateFormatter as we need to support iOS < 10
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss'Z'";
dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
formatter = dateFormatter;
});

return [formatter stringFromDate:date];
Expand Down

0 comments on commit e039423

Please sign in to comment.