UserLoginFastCell.m 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // UserLoginFastCell.m
  3. // XenonSDK
  4. //
  5. // Created by SAGESSE on 2019/5/30.
  6. // Copyright © 2019 SAGESSE. All rights reserved.
  7. //
  8. #import "XenonSDK.h"
  9. #import "UserLoginFastCell.h"
  10. @implementation UserLoginFastCell
  11. - (void)setUser:(XSUser*)user {
  12. _user = user;
  13. NSTimeInterval lasttime = user.lastTime;
  14. NSTimeInterval diff = NSDate.new.timeIntervalSince1970 - lasttime;
  15. id str = @"很久以前";
  16. if (diff < 60) {
  17. str = @"刚刚";
  18. } else if (diff < 3600) {
  19. str = [NSString stringWithFormat:@"%zd分钟前", (NSInteger)(diff / 60)];
  20. } else if (diff < 86400) {
  21. str = [NSString stringWithFormat:@"%zd小时前", (NSInteger)(diff / 60 / 60)];
  22. } else if (diff < 2592000) {
  23. str = [NSString stringWithFormat:@"%zd天前", (NSInteger)(diff / 60 / 60 / 24)];
  24. }
  25. self.titleLabel.text = user.account ?: [NSString stringWithFormat:@"游客 - %@", user.userName ?: @""];
  26. self.subtitleLabel.text = [NSString stringWithFormat:@"上次登录 %@", str];
  27. }
  28. @end