GTLRDateTime.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* Copyright (c) 2011 Google Inc.
  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. */
  15. #import <Foundation/Foundation.h>
  16. #import "GTLRDefines.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /**
  19. * An immutable class representing a date and optionally a time in UTC.
  20. */
  21. @interface GTLRDateTime : NSObject <NSCopying>
  22. /**
  23. * Constructor from a string representation.
  24. */
  25. + (nullable instancetype)dateTimeWithRFC3339String:(nullable NSString *)str;
  26. /**
  27. * Constructor from a date and time representation.
  28. */
  29. + (instancetype)dateTimeWithDate:(NSDate *)date;
  30. /**
  31. * Constructor from a date and time representation, along with an offset
  32. * minutes value used when creating a RFC3339 string representation.
  33. *
  34. * The date value is independent of time zone; the offset affects how the
  35. * date will be rendered as a string.
  36. *
  37. * The offsetMinutes may be initialized from a NSTimeZone as
  38. * (timeZone.secondsFromGMT / 60)
  39. */
  40. + (instancetype)dateTimeWithDate:(NSDate *)date
  41. offsetMinutes:(NSInteger)offsetMinutes;
  42. /**
  43. * Constructor from a date for an all-day event.
  44. *
  45. * Use this constructor to create a @c GTLRDateTime that is "date only".
  46. *
  47. * @note @c hasTime will be set to NO.
  48. */
  49. + (instancetype)dateTimeForAllDayWithDate:(NSDate *)date;
  50. /**
  51. * Constructor from date components.
  52. */
  53. + (instancetype)dateTimeWithDateComponents:(NSDateComponents *)date;
  54. /**
  55. * The represented date and time.
  56. *
  57. * If @c hasTime is NO, the time is set to noon GMT so the date is valid for all time zones.
  58. */
  59. @property(nonatomic, readonly) NSDate *date;
  60. /**
  61. * The date and time as a RFC3339 string representation.
  62. */
  63. @property(nonatomic, readonly) NSString *RFC3339String;
  64. /**
  65. * The date and time as a RFC3339 string representation.
  66. *
  67. * This returns the same string as @c RFC3339String.
  68. */
  69. @property(nonatomic, readonly) NSString *stringValue;
  70. /**
  71. * The represented date and time as date components.
  72. */
  73. @property(nonatomic, readonly, copy) NSDateComponents *dateComponents;
  74. /**
  75. * The fraction of seconds represented, 0-999.
  76. */
  77. @property(nonatomic, readonly) NSInteger milliseconds;
  78. /**
  79. * The time offset displayed in the string representation, if any.
  80. *
  81. * If the offset is not nil, the date and time will be rendered as a string
  82. * for the time zone indicated by the offset.
  83. *
  84. * An app may create a NSTimeZone for this with
  85. * [NSTimeZone timeZoneForSecondsFromGMT:(offsetMinutes.integerValue * 60)]
  86. */
  87. @property(nonatomic, readonly, nullable) NSNumber *offsetMinutes;
  88. /**
  89. * Flag indicating if the object represents date only, or date with time.
  90. */
  91. @property(nonatomic, readonly) BOOL hasTime;
  92. /**
  93. * The calendar used by this class, Gregorian and UTC.
  94. */
  95. + (NSCalendar *)calendar;
  96. @end
  97. NS_ASSUME_NONNULL_END