FPRSessionDetails.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. detailsCopy.sessionCreationTime = _sessionCreationTime;
  33. return detailsCopy;
  34. }
  35. - (NSUInteger)sessionLengthInMinutes {
  36. NSTimeInterval sessionLengthInSeconds = ABS([self.sessionCreationTime timeIntervalSinceNow]);
  37. return (NSUInteger)(sessionLengthInSeconds / 60);
  38. }
  39. - (BOOL)isEqual:(FPRSessionDetails *)detailsObject {
  40. if (self.sessionId == detailsObject.sessionId) {
  41. return YES;
  42. }
  43. return NO;
  44. }
  45. - (BOOL)isVerbose {
  46. return (self.options > FPRSessionOptionsNone);
  47. }
  48. @end