NSDate+ZZExTest.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // NSDate+ZZExTest.m
  3. // ZZFoundation_Tests
  4. //
  5. // Created by Max on 2020/12/29.
  6. // Copyright © 2020 bymiracles@163.com. All rights reserved.
  7. //
  8. #import "Kiwi.h"
  9. #import <ZZFoundation.h>
  10. SPEC_BEGIN(DateEx)
  11. __block NSDate * yearlastWeek;
  12. __block NSDate * sometoday;
  13. describe(@"week", ^{
  14. beforeEach(^{
  15. NSDateFormatter *format = [[NSDateFormatter alloc] init];
  16. format.dateFormat = @"yyyy-MM-dd Z";
  17. yearlastWeek = [format dateFromString:@"2020-12-22 +0800"];
  18. sometoday = [format dateFromString:@"2020-12-30 +0800"];
  19. });
  20. it(@"this week should be nth of this month", ^{
  21. [[theValue([sometoday weekOfMonth]) should] equal:theValue(5)];
  22. });
  23. it(@"this week should be nth of this year", ^{
  24. //w: 1~53 (0 padded Week of Year, 1st day of week = Sunday, NB: 1st week of year starts from the last Sunday of last year)
  25. NSLog(@"%zd",[yearlastWeek weekOfYear]);
  26. [[theValue([yearlastWeek weekOfYear]) should] beGreaterThanOrEqualTo:theValue(51)];
  27. });
  28. it(@"time should be correct", ^{
  29. NSDateFormatter *format = [[NSDateFormatter alloc] init];
  30. [format setDateFormat:@"yyyy-MM-dd HH时"];
  31. [[[format stringFromDate:sometoday] should] equal:@"2020-12-30 11时"];
  32. });
  33. });
  34. SPEC_END