FPRSessionDetails.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "FirebasePerformance/Sources/AppActivity/FPRSessionDetails.h"
  15. @interface FPRSessionDetails ()
  16. /** @brief Time at which the session was created. */
  17. @property(nonatomic) NSDate *sessionCreationTime;
  18. @end
  19. @implementation FPRSessionDetails
  20. - (instancetype)initWithSessionId:(NSString *)sessionId options:(FPRSessionOptions)options {
  21. self = [super init];
  22. if (self) {
  23. _sessionId = sessionId;
  24. _options = options;
  25. _sessionCreationTime = [NSDate date];
  26. }
  27. return self;
  28. }
  29. - (FPRSessionDetails *)copyWithZone:(NSZone *)zone {
  30. FPRSessionDetails *detailsCopy = [[[self class] allocWithZone:zone] initWithSessionId:_sessionId
  31. options:_options];
  32. return detailsCopy;
  33. }
  34. - (NSUInteger)sessionLengthInMinutes {
  35. NSTimeInterval sessionLengthInSeconds = ABS([self.sessionCreationTime timeIntervalSinceNow]);
  36. return (sessionLengthInSeconds / 60);
  37. }
  38. - (BOOL)isEqual:(FPRSessionDetails *)detailsObject {
  39. if (self.sessionId == detailsObject.sessionId) {
  40. return YES;
  41. }
  42. return NO;
  43. }
  44. - (BOOL)isVerbose {
  45. return (self.options > FPRSessionOptionsNone);
  46. }
  47. @end