Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当手机系统时区与设置的BRDatePickerView.timeZone时区不一致时闪退,报错"最小日期不能大于最大日期!" #308

Closed
bikeboy7 opened this issue May 25, 2024 · 6 comments

Comments

@bikeboy7
Copy link

Xcode: 15.1
iOS:16.7
语言:swift
系统时区:上海
BRDatePickerView.timeZone:纽约
BRDatePickerView.pickerMode = BRDatePickerModeCountDownTimer
minDate = nil
maxDate = nil

运行结果:闪退,报错"最小日期不能大于最大日期!"
当给 minDate、maxDate 赋值不为nil,就正常了,应该是br_compareDate这个方法出问题了

@agiapp agiapp closed this as completed in 8213aa6 May 28, 2024
@agiapp
Copy link
Owner

agiapp commented May 28, 2024

已修复,请使用最新版本进行使用。是时区不同步问题,针对自定义时区问题,你可以再多测试一下,看看有没有其他问题。

@bikeboy7
Copy link
Author

第一次显示picker时,br_setTimeZone 方法中 _sharedCalendar 为nil,时区设置失败,还是会出现同样的问题

测试代码:
@implementation TestViewController

  • (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    BRDatePickerView *picker = [[BRDatePickerView alloc] initWithPickerMode:BRDatePickerModeTime];
    picker.timeZone = [NSTimeZone timeZoneWithName:@"America/New_York"];
    [picker show];
    picker.resultBlock = ^(NSDate *date, NSString *str){
    NSLog(@"%@", date);
    };
    }

//- (void)viewDidLoad {
// [super viewDidLoad];
// self.navigationItem.title = @"Demo";
// self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"其它" style:UIBarButtonItemStylePlain target:self action:@selector(clickGotoTest2VC)];
// self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(clickSaveBtn)];
// [self loadData];
// [self initUI];
//}

@agiapp
Copy link
Owner

agiapp commented May 28, 2024

多谢提醒👍🏻

修改代码如下,你看一下还有没有问题,针对时区的场景需要多测试一下。

#pragma mark - 设置时区
+ (void)br_setTimeZone:(NSTimeZone *)timeZone {
    _timeZone = timeZone;
    [self br_getCalendar].timeZone = timeZone;
    //_sharedCalendar.timeZone = timeZone;
}

@bikeboy7
Copy link
Author

可以了

@agiapp
Copy link
Owner

agiapp commented May 28, 2024

好的,我等下把代码同步上去

@agiapp
Copy link
Owner

agiapp commented May 28, 2024

代码和pod都已更新

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants