-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathGTTimeAdditionsSpec.m
More file actions
52 lines (42 loc) · 1.73 KB
/
Copy pathGTTimeAdditionsSpec.m
File metadata and controls
52 lines (42 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// GTTimeAdditionsSpec.m
// ObjectiveGitFramework
//
// Created by Danny Greg on 27/03/2013.
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
//
#import <Nimble/Nimble.h>
#import <ObjectiveGit/ObjectiveGit.h>
#import <Quick/Quick.h>
#import "QuickSpec+GTFixtures.h"
QuickSpecBegin(GTTimeAdditions)
describe(@"Conversion between git_time and NSDate", ^{
it(@"should be able to create a correct NSDate and NSTimeZone when given a git_time", ^{
git_time_t seconds = 1265374800;
int offset = -120; //2 hours behind GMT
git_time time = (git_time){ .time = seconds, .offset = offset };
NSDate *date = [NSDate gt_dateFromGitTime:time];
expect(date).notTo(beNil());
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
gregorianCalendar.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
NSDateComponents *components = [gregorianCalendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear | NSCalendarUnitHour fromDate:date];
expect(components).notTo(beNil());
expect(@(components.day)).to(equal(@5));
expect(@(components.month)).to(equal(@2));
expect(@(components.year)).to(equal(@2010));
expect(@(components.hour)).to(equal(@13));
NSTimeZone *timeZone = [NSTimeZone gt_timeZoneFromGitTime:time];
expect(timeZone).notTo(beNil());
NSInteger expectedSecondsFromGMT = -120 * 60;
expect(@(timeZone.secondsFromGMT)).to(equal(@(expectedSecondsFromGMT)));
});
it(@"should return a correct offset for an NSTimeZone", ^{
NSTimeZone *timeZone = [NSTimeZone timeZoneForSecondsFromGMT:180 * 60];
expect(timeZone).notTo(beNil());
expect(@(timeZone.gt_gitTimeOffset)).to(equal(@180));
});
});
afterEach(^{
[self tearDown];
});
QuickSpecEnd