Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit fe09f1ce
由
cgx
编写于
2022-04-25 18:06:57 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
完成用户生日修改
1 个父辈
82b6fc5a
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
1478 行增加
和
10 行删除
DreamSleep/DreamSleep.xcodeproj/project.pbxproj
DreamSleep/DreamSleep/Profile/Account/UserInfoTableView.m
DreamSleep/DreamSleep/Profile/UserLogin/LoginUtils.h
DreamSleep/DreamSleep/Profile/UserLogin/LoginUtils.m
DreamSleep/DreamSleep/Vendors/WSDaePickerView/NSDate+Extension.h
DreamSleep/DreamSleep/Vendors/WSDaePickerView/NSDate+Extension.m
DreamSleep/DreamSleep/Vendors/WSDaePickerView/WSDatePickerView.h
DreamSleep/DreamSleep/Vendors/WSDaePickerView/WSDatePickerView.m
DreamSleep/DreamSleep/Vendors/WSDaePickerView/WSDatePickerView.xib
DreamSleep/DreamSleep.xcodeproj/project.pbxproj
查看文件 @
fe09f1c
...
@@ -17,6 +17,9 @@
...
@@ -17,6 +17,9 @@
D01814EB28002A8200583D4E /* DsMiddleView.m in Sources */ = {isa = PBXBuildFile; fileRef = D01814EA28002A8200583D4E /* DsMiddleView.m */; };
D01814EB28002A8200583D4E /* DsMiddleView.m in Sources */ = {isa = PBXBuildFile; fileRef = D01814EA28002A8200583D4E /* DsMiddleView.m */; };
D01814EE28002DC700583D4E /* HeaderDataModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D01814ED28002DC700583D4E /* HeaderDataModel.m */; };
D01814EE28002DC700583D4E /* HeaderDataModel.m in Sources */ = {isa = PBXBuildFile; fileRef = D01814ED28002DC700583D4E /* HeaderDataModel.m */; };
D01C9D6728167F9D00163567 /* InfoModifyAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = D01C9D6628167F9D00163567 /* InfoModifyAlertView.m */; };
D01C9D6728167F9D00163567 /* InfoModifyAlertView.m in Sources */ = {isa = PBXBuildFile; fileRef = D01C9D6628167F9D00163567 /* InfoModifyAlertView.m */; };
D01C9D6E28168BFC00163567 /* WSDatePickerView.xib in Resources */ = {isa = PBXBuildFile; fileRef = D01C9D6B28168BFC00163567 /* WSDatePickerView.xib */; };
D01C9D6F28168BFC00163567 /* WSDatePickerView.m in Sources */ = {isa = PBXBuildFile; fileRef = D01C9D6C28168BFC00163567 /* WSDatePickerView.m */; };
D01C9D7028168BFC00163567 /* NSDate+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = D01C9D6D28168BFC00163567 /* NSDate+Extension.m */; };
D020CE1F280D951400E7E82F /* invite_friend.webp in Resources */ = {isa = PBXBuildFile; fileRef = D020CE1E280D915D00E7E82F /* invite_friend.webp */; };
D020CE1F280D951400E7E82F /* invite_friend.webp in Resources */ = {isa = PBXBuildFile; fileRef = D020CE1E280D915D00E7E82F /* invite_friend.webp */; };
D027EE2627FB3DC0004BBA61 /* NetLoadingStateView.m in Sources */ = {isa = PBXBuildFile; fileRef = D027EE2527FB3DC0004BBA61 /* NetLoadingStateView.m */; };
D027EE2627FB3DC0004BBA61 /* NetLoadingStateView.m in Sources */ = {isa = PBXBuildFile; fileRef = D027EE2527FB3DC0004BBA61 /* NetLoadingStateView.m */; };
D027EE2927FB51D0004BBA61 /* DSGifHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = D027EE2827FB51D0004BBA61 /* DSGifHeader.m */; };
D027EE2927FB51D0004BBA61 /* DSGifHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = D027EE2827FB51D0004BBA61 /* DSGifHeader.m */; };
...
@@ -143,6 +146,11 @@
...
@@ -143,6 +146,11 @@
D01814ED28002DC700583D4E /* HeaderDataModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HeaderDataModel.m; sourceTree = "<group>"; };
D01814ED28002DC700583D4E /* HeaderDataModel.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HeaderDataModel.m; sourceTree = "<group>"; };
D01C9D6528167F9D00163567 /* InfoModifyAlertView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InfoModifyAlertView.h; sourceTree = "<group>"; };
D01C9D6528167F9D00163567 /* InfoModifyAlertView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = InfoModifyAlertView.h; sourceTree = "<group>"; };
D01C9D6628167F9D00163567 /* InfoModifyAlertView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InfoModifyAlertView.m; sourceTree = "<group>"; };
D01C9D6628167F9D00163567 /* InfoModifyAlertView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InfoModifyAlertView.m; sourceTree = "<group>"; };
D01C9D6928168BFC00163567 /* NSDate+Extension.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDate+Extension.h"; sourceTree = "<group>"; };
D01C9D6A28168BFC00163567 /* WSDatePickerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WSDatePickerView.h; sourceTree = "<group>"; };
D01C9D6B28168BFC00163567 /* WSDatePickerView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = WSDatePickerView.xib; sourceTree = "<group>"; };
D01C9D6C28168BFC00163567 /* WSDatePickerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WSDatePickerView.m; sourceTree = "<group>"; };
D01C9D6D28168BFC00163567 /* NSDate+Extension.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDate+Extension.m"; sourceTree = "<group>"; };
D020CE1E280D915D00E7E82F /* invite_friend.webp */ = {isa = PBXFileReference; lastKnownFileType = file; path = invite_friend.webp; sourceTree = "<group>"; };
D020CE1E280D915D00E7E82F /* invite_friend.webp */ = {isa = PBXFileReference; lastKnownFileType = file; path = invite_friend.webp; sourceTree = "<group>"; };
D027EE2427FB3DC0004BBA61 /* NetLoadingStateView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NetLoadingStateView.h; sourceTree = "<group>"; };
D027EE2427FB3DC0004BBA61 /* NetLoadingStateView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NetLoadingStateView.h; sourceTree = "<group>"; };
D027EE2527FB3DC0004BBA61 /* NetLoadingStateView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NetLoadingStateView.m; sourceTree = "<group>"; };
D027EE2527FB3DC0004BBA61 /* NetLoadingStateView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NetLoadingStateView.m; sourceTree = "<group>"; };
...
@@ -390,6 +398,18 @@
...
@@ -390,6 +398,18 @@
path = DataSource;
path = DataSource;
sourceTree = "<group>";
sourceTree = "<group>";
};
};
D01C9D6828168BFC00163567 /* WSDaePickerView */ = {
isa = PBXGroup;
children = (
D01C9D6928168BFC00163567 /* NSDate+Extension.h */,
D01C9D6A28168BFC00163567 /* WSDatePickerView.h */,
D01C9D6B28168BFC00163567 /* WSDatePickerView.xib */,
D01C9D6C28168BFC00163567 /* WSDatePickerView.m */,
D01C9D6D28168BFC00163567 /* NSDate+Extension.m */,
);
path = WSDaePickerView;
sourceTree = "<group>";
};
D027EE2327FB3C99004BBA61 /* Network */ = {
D027EE2327FB3C99004BBA61 /* Network */ = {
isa = PBXGroup;
isa = PBXGroup;
children = (
children = (
...
@@ -813,10 +833,11 @@
...
@@ -813,10 +833,11 @@
D0E9408127FE961300D57495 /* Vendors */ = {
D0E9408127FE961300D57495 /* Vendors */ = {
isa = PBXGroup;
isa = PBXGroup;
children = (
children = (
D07DAC912810557D0067A1BF /* RSKImageCropper */,
D046FDF528100342000295AC /* UMSocial_6.10.4 */,
D01814D927FFD91100583D4E /* DataSource */,
D01814D927FFD91100583D4E /* DataSource */,
D01814CA27FFCBAF00583D4E /* CWCarousel */,
D01814CA27FFCBAF00583D4E /* CWCarousel */,
D046FDF528100342000295AC /* UMSocial_6.10.4 */,
D01C9D6828168BFC00163567 /* WSDaePickerView */,
D07DAC912810557D0067A1BF /* RSKImageCropper */,
D0E65FF32807A654006562F2 /* HYBUnicodeReadable */,
D0E65FF32807A654006562F2 /* HYBUnicodeReadable */,
D0878F49280BEFF9005F1B7F /* YBAttributeTextTapAction */,
D0878F49280BEFF9005F1B7F /* YBAttributeTextTapAction */,
);
);
...
@@ -972,6 +993,7 @@
...
@@ -972,6 +993,7 @@
buildActionMask = 2147483647;
buildActionMask = 2147483647;
files = (
files = (
D0C09ED728007D9100709D4C /* relax_normal_lottie.json in Resources */,
D0C09ED728007D9100709D4C /* relax_normal_lottie.json in Resources */,
D01C9D6E28168BFC00163567 /* WSDatePickerView.xib in Resources */,
D0C09ED828007D9100709D4C /* 478_lottie.json in Resources */,
D0C09ED828007D9100709D4C /* 478_lottie.json in Resources */,
D046FE0D28100342000295AC /* UMSocialSDKResources.bundle in Resources */,
D046FE0D28100342000295AC /* UMSocialSDKResources.bundle in Resources */,
D04B3DB327F6F6070022F8DF /* Home.storyboard in Resources */,
D04B3DB327F6F6070022F8DF /* Home.storyboard in Resources */,
...
@@ -1053,6 +1075,7 @@
...
@@ -1053,6 +1075,7 @@
D0E65FFB2807A654006562F2 /* NSDictionary+HYBUnicodeReadable.m in Sources */,
D0E65FFB2807A654006562F2 /* NSDictionary+HYBUnicodeReadable.m in Sources */,
D0E65FFA2807A654006562F2 /* NSArray+HYBUnicodeReadable.m in Sources */,
D0E65FFA2807A654006562F2 /* NSArray+HYBUnicodeReadable.m in Sources */,
D04B3DC027F6F82D0022F8DF /* ProfileController.m in Sources */,
D04B3DC027F6F82D0022F8DF /* ProfileController.m in Sources */,
D01C9D7028168BFC00163567 /* NSDate+Extension.m in Sources */,
D0C50B3027FD1BEB00DC68F0 /* PrivacyView.m in Sources */,
D0C50B3027FD1BEB00DC68F0 /* PrivacyView.m in Sources */,
D0B5ECD527F2F0B2003EDFE3 /* AdaptationUtil.m in Sources */,
D0B5ECD527F2F0B2003EDFE3 /* AdaptationUtil.m in Sources */,
D0F8090428042A0B0097899F /* SafeSleepCell.m in Sources */,
D0F8090428042A0B0097899F /* SafeSleepCell.m in Sources */,
...
@@ -1123,6 +1146,7 @@
...
@@ -1123,6 +1146,7 @@
D027EE3027FB52DA004BBA61 /* UIImage+Extras.m in Sources */,
D027EE3027FB52DA004BBA61 /* UIImage+Extras.m in Sources */,
D0506B1828054ECD00229278 /* SafeHelperCollectionView.m in Sources */,
D0506B1828054ECD00229278 /* SafeHelperCollectionView.m in Sources */,
D04B3DC327F6F9390022F8DF /* HomeViewController.m in Sources */,
D04B3DC327F6F9390022F8DF /* HomeViewController.m in Sources */,
D01C9D6F28168BFC00163567 /* WSDatePickerView.m in Sources */,
);
);
runOnlyForDeploymentPostprocessing = 0;
runOnlyForDeploymentPostprocessing = 0;
};
};
...
@@ -1312,7 +1336,7 @@
...
@@ -1312,7 +1336,7 @@
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/WeChat/WechatSDK",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/WeChat/WechatSDK",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/QQ",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/QQ",
);
);
MARKETING_VERSION = 1.1.
1
;
MARKETING_VERSION = 1.1.
2
;
ONLY_ACTIVE_ARCH = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
OTHER_LDFLAGS = (
"$(inherited)",
"$(inherited)",
...
@@ -1353,7 +1377,7 @@
...
@@ -1353,7 +1377,7 @@
GENERATE_INFOPLIST_FILE = YES;
GENERATE_INFOPLIST_FILE = YES;
HEADER_SEARCH_PATHS = "$(inherited)/**";
HEADER_SEARCH_PATHS = "$(inherited)/**";
INFOPLIST_FILE = DreamSleep/DSConfig/Info.plist;
INFOPLIST_FILE = DreamSleep/DSConfig/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "小梦睡眠";
INFOPLIST_KEY_CFBundleDisplayName = "小梦睡眠
-Dev
";
INFOPLIST_KEY_NSCameraUsageDescription = "APP需要访问您的相机。";
INFOPLIST_KEY_NSCameraUsageDescription = "APP需要访问您的相机。";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
...
@@ -1373,7 +1397,7 @@
...
@@ -1373,7 +1397,7 @@
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/WeChat/WechatSDK",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/WeChat/WechatSDK",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/QQ",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/QQ",
);
);
MARKETING_VERSION = 1.1.
1
;
MARKETING_VERSION = 1.1.
2
;
ONLY_ACTIVE_ARCH = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
OTHER_LDFLAGS = (
"$(inherited)",
"$(inherited)",
...
@@ -1474,7 +1498,7 @@
...
@@ -1474,7 +1498,7 @@
GENERATE_INFOPLIST_FILE = YES;
GENERATE_INFOPLIST_FILE = YES;
HEADER_SEARCH_PATHS = "$(inherited)/**";
HEADER_SEARCH_PATHS = "$(inherited)/**";
INFOPLIST_FILE = DreamSleep/DSConfig/Info.plist;
INFOPLIST_FILE = DreamSleep/DSConfig/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "小梦睡眠-
Beta
";
INFOPLIST_KEY_CFBundleDisplayName = "小梦睡眠-
Dev
";
INFOPLIST_KEY_NSCameraUsageDescription = "APP需要访问您的相机。";
INFOPLIST_KEY_NSCameraUsageDescription = "APP需要访问您的相机。";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
...
@@ -1494,7 +1518,7 @@
...
@@ -1494,7 +1518,7 @@
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/WeChat/WechatSDK",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/WeChat/WechatSDK",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/QQ",
"$(PROJECT_DIR)/DreamSleep/Vendors/UMSocial_6.10.4/SocialLibraries/QQ",
);
);
MARKETING_VERSION = 1.1.
1
;
MARKETING_VERSION = 1.1.
2
;
ONLY_ACTIVE_ARCH = YES;
ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = (
OTHER_LDFLAGS = (
"$(inherited)",
"$(inherited)",
...
...
DreamSleep/DreamSleep/Profile/Account/UserInfoTableView.m
查看文件 @
fe09f1c
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#import "UserInfoTableView.h"
#import "UserInfoTableView.h"
#import "NickNameController.h"
#import "NickNameController.h"
#import "InfoModifyAlertView.h"
#import "InfoModifyAlertView.h"
#import "WSDatePickerView.h"
/// 自定义用户信息显示数据model
/// 自定义用户信息显示数据model
@interface
UserShowModel
:
NSObject
@interface
UserShowModel
:
NSObject
...
@@ -138,15 +139,39 @@
...
@@ -138,15 +139,39 @@
InfoModifyAlertView
*
genderView
=
[[
InfoModifyAlertView
alloc
]
initWithDelegate
:
self
type
:
AlertTypeGender
];
InfoModifyAlertView
*
genderView
=
[[
InfoModifyAlertView
alloc
]
initWithDelegate
:
self
type
:
AlertTypeGender
];
[
genderView
showInfoModifyAlertView
];
[
genderView
showInfoModifyAlertView
];
}
else
if
(
indexPath
.
row
==
2
)
{
// 修改生日
}
else
if
(
indexPath
.
row
==
2
)
{
// 修改生日
WS
(
weakSelf
);
NSDate
*
birthDate
=
[
NSDate
date
:[
LoginUtils
getBirthday
]
WithFormat
:
@"yyyy-MM-dd"
];
NSDate
*
defaultDate
=
[
NSDate
date
:
@"1975-07-15"
WithFormat
:
@"yyyy-MM-dd"
];
NSDate
*
scrollDate
=
birthDate
?
birthDate
:
defaultDate
;
WSDatePickerView
*
datepicker
=
[[
WSDatePickerView
alloc
]
initWithDateStyle
:
DateStyleShowYearMonthDay
scrollToDate
:
scrollDate
CompleteBlock
:^
(
NSDate
*
selectDate
)
{
NSDateFormatter
*
dateFormatter
=
[[
NSDateFormatter
alloc
]
init
];
[
dateFormatter
setDateFormat
:
@"yyyy-MM-dd"
];
NSString
*
selectDateStr
=
[
dateFormatter
stringFromDate
:
selectDate
];
NSDictionary
*
data
=
@{
@"birthday"
:
selectDateStr
};
[
DSProgressHUD
showProgressHUDWithInfo
:
@""
];
[
UserRequestModel
updateUserInfoWithData
:
data
completion
:
^
(
UserRequestModel
*
_Nonnull
requestModel
)
{
[
DSProgressHUD
dissmissProgressHUD
];
if
(
requestModel
.
resCode
==
DSResCodeSuccess
)
{
[
DSProgressHUD
showToast
:
@"修改成功"
];
[
LoginUtils
updateUserInfo
:
data
];
[
weakSelf
.
infoDataSource
addDataArray
:[
UserShowModel
getUserShowDatas
]];
[
weakSelf
reloadData
];
}
}];
}];
[
datepicker
setMinLimitDate
:[
NSDate
date
:
@"1930-01-01"
WithFormat
:
@"yyyy-MM-dd"
]];
[
datepicker
setMaxLimitDate
:[
NSDate
date
]];
[
datepicker
show
];
}
}
}
}
#pragma mark - InfoModifyAlertViewDelegate
#pragma mark - InfoModifyAlertViewDelegate
&& 修改性别请求
-
(
void
)
didSelectWithType
:
(
AlertType
)
type
index
:
(
int
)
index
{
-
(
void
)
didSelectWithType
:
(
AlertType
)
type
index
:
(
int
)
index
{
[
DSProgressHUD
showProgressHUDWithInfo
:
@""
];
NSDictionary
*
data
=
@{
@"gender"
:
@
(
index
==
1
?
1
:
0
)};
WS
(
weakSelf
);
WS
(
weakSelf
);
NSDictionary
*
data
=
@{
@"gender"
:
@
(
index
==
1
?
1
:
0
)};
[
DSProgressHUD
showProgressHUDWithInfo
:
@""
];
[
UserRequestModel
updateUserInfoWithData
:
data
completion
:
^
(
UserRequestModel
*
_Nonnull
requestModel
)
{
[
UserRequestModel
updateUserInfoWithData
:
data
completion
:
^
(
UserRequestModel
*
_Nonnull
requestModel
)
{
[
DSProgressHUD
dissmissProgressHUD
];
[
DSProgressHUD
dissmissProgressHUD
];
if
(
requestModel
.
resCode
==
DSResCodeSuccess
)
{
if
(
requestModel
.
resCode
==
DSResCodeSuccess
)
{
...
...
DreamSleep/DreamSleep/Profile/UserLogin/LoginUtils.h
查看文件 @
fe09f1c
...
@@ -28,6 +28,9 @@ NS_ASSUME_NONNULL_BEGIN
...
@@ -28,6 +28,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 获取用户头像
/// 获取用户头像
+
(
NSString
*
)
getFaceImg
;
+
(
NSString
*
)
getFaceImg
;
/// 获取用户生日
+
(
NSString
*
)
getBirthday
;
/// 更新sid和token
/// 更新sid和token
/// @param sid sid
/// @param sid sid
/// @param token token
/// @param token token
...
...
DreamSleep/DreamSleep/Profile/UserLogin/LoginUtils.m
查看文件 @
fe09f1c
...
@@ -35,6 +35,11 @@
...
@@ -35,6 +35,11 @@
return
userModel
.
face_img
;
return
userModel
.
face_img
;
}
}
+
(
NSString
*
)
getBirthday
{
UserModel
*
userModel
=
[
self
getUserLoginData
];
return
userModel
.
birthday
;
}
+
(
void
)
updateSid
:
(
NSString
*
)
sid
token
:
(
NSString
*
)
token
{
+
(
void
)
updateSid
:
(
NSString
*
)
sid
token
:
(
NSString
*
)
token
{
UserModel
*
userModel
=
[
self
getUserLoginData
];
UserModel
*
userModel
=
[
self
getUserLoginData
];
userModel
.
sid
=
sid
;
userModel
.
sid
=
sid
;
...
...
DreamSleep/DreamSleep/Vendors/WSDaePickerView/NSDate+Extension.h
0 → 100755
查看文件 @
fe09f1c
//
// NSDate+Extension.h
// SmartLock
//
// Created by 江欣华 on 2016/10/25.
// Copyright © 2016年 工程锁. All rights reserved.
//
#import <Foundation/Foundation.h>
#define D_MINUTE 60
#define D_HOUR 3600
#define D_DAY 86400
#define D_WEEK 604800
#define D_YEAR 31556926
@interface
NSDate
(
Extension
)
+
(
NSCalendar
*
)
currentCalendar
;
// avoid bottlenecks
// Relative dates from the current date
+
(
NSDate
*
)
dateTomorrow
;
+
(
NSDate
*
)
dateYesterday
;
+
(
NSDate
*
)
dateWithDaysFromNow
:
(
NSInteger
)
days
;
+
(
NSDate
*
)
dateWithDaysBeforeNow
:
(
NSInteger
)
days
;
+
(
NSDate
*
)
dateWithHoursFromNow
:
(
NSInteger
)
dHours
;
+
(
NSDate
*
)
dateWithHoursBeforeNow
:
(
NSInteger
)
dHours
;
+
(
NSDate
*
)
dateWithMinutesFromNow
:
(
NSInteger
)
dMinutes
;
+
(
NSDate
*
)
dateWithMinutesBeforeNow
:
(
NSInteger
)
dMinutes
;
+
(
NSDate
*
)
date
:(
NSString
*
)
datestr
WithFormat
:(
NSString
*
)
format
;
// Short string utilities
-
(
NSString
*
)
stringWithDateStyle
:
(
NSDateFormatterStyle
)
dateStyle
timeStyle
:
(
NSDateFormatterStyle
)
timeStyle
;
-
(
NSString
*
)
stringWithFormat
:
(
NSString
*
)
format
;
@property
(
nonatomic
,
readonly
)
NSString
*
shortString
;
@property
(
nonatomic
,
readonly
)
NSString
*
shortDateString
;
@property
(
nonatomic
,
readonly
)
NSString
*
shortTimeString
;
@property
(
nonatomic
,
readonly
)
NSString
*
mediumString
;
@property
(
nonatomic
,
readonly
)
NSString
*
mediumDateString
;
@property
(
nonatomic
,
readonly
)
NSString
*
mediumTimeString
;
@property
(
nonatomic
,
readonly
)
NSString
*
longString
;
@property
(
nonatomic
,
readonly
)
NSString
*
longDateString
;
@property
(
nonatomic
,
readonly
)
NSString
*
longTimeString
;
// Comparing dates
-
(
BOOL
)
isEqualToDateIgnoringTime
:
(
NSDate
*
)
aDate
;
-
(
BOOL
)
isToday
;
-
(
BOOL
)
isTomorrow
;
-
(
BOOL
)
isYesterday
;
-
(
BOOL
)
isSameWeekAsDate
:
(
NSDate
*
)
aDate
;
-
(
BOOL
)
isThisWeek
;
-
(
BOOL
)
isNextWeek
;
-
(
BOOL
)
isLastWeek
;
-
(
BOOL
)
isSameMonthAsDate
:
(
NSDate
*
)
aDate
;
-
(
BOOL
)
isThisMonth
;
-
(
BOOL
)
isNextMonth
;
-
(
BOOL
)
isLastMonth
;
-
(
BOOL
)
isSameYearAsDate
:
(
NSDate
*
)
aDate
;
-
(
BOOL
)
isThisYear
;
-
(
BOOL
)
isNextYear
;
-
(
BOOL
)
isLastYear
;
-
(
BOOL
)
isEarlierThanDate
:
(
NSDate
*
)
aDate
;
-
(
BOOL
)
isLaterThanDate
:
(
NSDate
*
)
aDate
;
-
(
BOOL
)
isInFuture
;
-
(
BOOL
)
isInPast
;
// Date roles
-
(
BOOL
)
isTypicallyWorkday
;
-
(
BOOL
)
isTypicallyWeekend
;
// Adjusting dates
-
(
NSDate
*
)
dateByAddingYears
:
(
NSInteger
)
dYears
;
-
(
NSDate
*
)
dateBySubtractingYears
:
(
NSInteger
)
dYears
;
-
(
NSDate
*
)
dateByAddingMonths
:
(
NSInteger
)
dMonths
;
-
(
NSDate
*
)
dateBySubtractingMonths
:
(
NSInteger
)
dMonths
;
-
(
NSDate
*
)
dateByAddingDays
:
(
NSInteger
)
dDays
;
-
(
NSDate
*
)
dateBySubtractingDays
:
(
NSInteger
)
dDays
;
-
(
NSDate
*
)
dateByAddingHours
:
(
NSInteger
)
dHours
;
-
(
NSDate
*
)
dateBySubtractingHours
:
(
NSInteger
)
dHours
;
-
(
NSDate
*
)
dateByAddingMinutes
:
(
NSInteger
)
dMinutes
;
-
(
NSDate
*
)
dateBySubtractingMinutes
:
(
NSInteger
)
dMinutes
;
// Date extremes
-
(
NSDate
*
)
dateAtStartOfDay
;
-
(
NSDate
*
)
dateAtEndOfDay
;
// Retrieving intervals
-
(
NSInteger
)
minutesAfterDate
:
(
NSDate
*
)
aDate
;
-
(
NSInteger
)
minutesBeforeDate
:
(
NSDate
*
)
aDate
;
-
(
NSInteger
)
hoursAfterDate
:
(
NSDate
*
)
aDate
;
-
(
NSInteger
)
hoursBeforeDate
:
(
NSDate
*
)
aDate
;
-
(
NSInteger
)
daysAfterDate
:
(
NSDate
*
)
aDate
;
-
(
NSInteger
)
daysBeforeDate
:
(
NSDate
*
)
aDate
;
-
(
NSInteger
)
distanceInDaysToDate
:(
NSDate
*
)
anotherDate
;
// Decomposing dates
@property
(
readonly
)
NSInteger
nearestHour
;
@property
(
readonly
)
NSInteger
hour
;
@property
(
readonly
)
NSInteger
minute
;
@property
(
readonly
)
NSInteger
seconds
;
@property
(
readonly
)
NSInteger
day
;
@property
(
readonly
)
NSInteger
month
;
@property
(
readonly
)
NSInteger
week
;
@property
(
readonly
)
NSInteger
weekday
;
@property
(
readonly
)
NSInteger
nthWeekday
;
// e.g. 2nd Tuesday of the month == 2
@property
(
readonly
)
NSInteger
year
;
-
(
NSDate
*
)
dateWithYMD
;
-
(
NSDate
*
)
dateWithFormatter
:(
NSString
*
)
formatter
;
@end
DreamSleep/DreamSleep/Vendors/WSDaePickerView/NSDate+Extension.m
0 → 100755
查看文件 @
fe09f1c
//
// NSDate+Extension.m
// SmartLock
//
// Created by 江欣华 on 2016/10/25.
// Copyright © 2016年 工程锁. All rights reserved.
//
#import "NSDate+Extension.h"
static
const
unsigned
componentFlags
=
(
NSCalendarUnitYear
|
NSCalendarUnitMonth
|
NSCalendarUnitDay
|
NSCalendarUnitWeekOfMonth
|
NSCalendarUnitHour
|
NSCalendarUnitMinute
|
NSCalendarUnitSecond
|
NSCalendarUnitWeekday
|
NSCalendarUnitWeekdayOrdinal
);
@implementation
NSDate
(
Extension
)
+
(
NSCalendar
*
)
currentCalendar
{
static
NSCalendar
*
sharedCalendar
=
nil
;
if
(
!
sharedCalendar
)
sharedCalendar
=
[
NSCalendar
autoupdatingCurrentCalendar
];
return
sharedCalendar
;
}
#pragma mark - Relative Dates
+
(
NSDate
*
)
dateWithDaysFromNow
:
(
NSInteger
)
days
{
// Thanks, Jim Morrison
return
[[
NSDate
date
]
dateByAddingDays
:
days
];
}
+
(
NSDate
*
)
dateWithDaysBeforeNow
:
(
NSInteger
)
days
{
// Thanks, Jim Morrison
return
[[
NSDate
date
]
dateBySubtractingDays
:
days
];
}
+
(
NSDate
*
)
dateTomorrow
{
return
[
NSDate
dateWithDaysFromNow
:
1
];
}
+
(
NSDate
*
)
dateYesterday
{
return
[
NSDate
dateWithDaysBeforeNow
:
1
];
}
+
(
NSDate
*
)
dateWithHoursFromNow
:
(
NSInteger
)
dHours
{
NSTimeInterval
aTimeInterval
=
[[
NSDate
date
]
timeIntervalSinceReferenceDate
]
+
D_HOUR
*
dHours
;
NSDate
*
newDate
=
[
NSDate
dateWithTimeIntervalSinceReferenceDate
:
aTimeInterval
];
return
newDate
;
}
+
(
NSDate
*
)
dateWithHoursBeforeNow
:
(
NSInteger
)
dHours
{
NSTimeInterval
aTimeInterval
=
[[
NSDate
date
]
timeIntervalSinceReferenceDate
]
-
D_HOUR
*
dHours
;
NSDate
*
newDate
=
[
NSDate
dateWithTimeIntervalSinceReferenceDate
:
aTimeInterval
];
return
newDate
;
}
+
(
NSDate
*
)
dateWithMinutesFromNow
:
(
NSInteger
)
dMinutes
{
NSTimeInterval
aTimeInterval
=
[[
NSDate
date
]
timeIntervalSinceReferenceDate
]
+
D_MINUTE
*
dMinutes
;
NSDate
*
newDate
=
[
NSDate
dateWithTimeIntervalSinceReferenceDate
:
aTimeInterval
];
return
newDate
;
}
+
(
NSDate
*
)
dateWithMinutesBeforeNow
:
(
NSInteger
)
dMinutes
{
NSTimeInterval
aTimeInterval
=
[[
NSDate
date
]
timeIntervalSinceReferenceDate
]
-
D_MINUTE
*
dMinutes
;
NSDate
*
newDate
=
[
NSDate
dateWithTimeIntervalSinceReferenceDate
:
aTimeInterval
];
return
newDate
;
}
#pragma mark - String Properties
-
(
NSString
*
)
stringWithFormat
:
(
NSString
*
)
format
{
NSDateFormatter
*
formatter
=
[
NSDateFormatter
new
];
// formatter.locale = [NSLocale currentLocale]; // Necessary?
formatter
.
dateFormat
=
format
;
return
[
formatter
stringFromDate
:
self
];
}
-
(
NSString
*
)
stringWithDateStyle
:
(
NSDateFormatterStyle
)
dateStyle
timeStyle
:
(
NSDateFormatterStyle
)
timeStyle
{
NSDateFormatter
*
formatter
=
[
NSDateFormatter
new
];
formatter
.
dateStyle
=
dateStyle
;
formatter
.
timeStyle
=
timeStyle
;
// formatter.locale = [NSLocale currentLocale]; // Necessary?
return
[
formatter
stringFromDate
:
self
];
}
-
(
NSString
*
)
shortString
{
return
[
self
stringWithDateStyle
:
NSDateFormatterShortStyle
timeStyle
:
NSDateFormatterShortStyle
];
}
-
(
NSString
*
)
shortTimeString
{
return
[
self
stringWithDateStyle
:
NSDateFormatterNoStyle
timeStyle
:
NSDateFormatterShortStyle
];
}
-
(
NSString
*
)
shortDateString
{
return
[
self
stringWithDateStyle
:
NSDateFormatterShortStyle
timeStyle
:
NSDateFormatterNoStyle
];
}
-
(
NSString
*
)
mediumString
{
return
[
self
stringWithDateStyle
:
NSDateFormatterMediumStyle
timeStyle
:
NSDateFormatterMediumStyle
];
}
-
(
NSString
*
)
mediumTimeString
{
return
[
self
stringWithDateStyle
:
NSDateFormatterNoStyle
timeStyle
:
NSDateFormatterMediumStyle
];
}
-
(
NSString
*
)
mediumDateString
{
return
[
self
stringWithDateStyle
:
NSDateFormatterMediumStyle
timeStyle
:
NSDateFormatterNoStyle
];
}
-
(
NSString
*
)
longString
{
return
[
self
stringWithDateStyle
:
NSDateFormatterLongStyle
timeStyle
:
NSDateFormatterLongStyle
];
}
-
(
NSString
*
)
longTimeString
{
return
[
self
stringWithDateStyle
:
NSDateFormatterNoStyle
timeStyle
:
NSDateFormatterLongStyle
];
}
-
(
NSString
*
)
longDateString
{
return
[
self
stringWithDateStyle
:
NSDateFormatterLongStyle
timeStyle
:
NSDateFormatterNoStyle
];
}
#pragma mark - Comparing Dates
-
(
BOOL
)
isEqualToDateIgnoringTime
:
(
NSDate
*
)
aDate
{
NSDateComponents
*
components1
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
NSDateComponents
*
components2
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
aDate
];
return
((
components1
.
year
==
components2
.
year
)
&&
(
components1
.
month
==
components2
.
month
)
&&
(
components1
.
day
==
components2
.
day
));
}
-
(
BOOL
)
isToday
{
return
[
self
isEqualToDateIgnoringTime
:[
NSDate
date
]];
}
-
(
BOOL
)
isTomorrow
{
return
[
self
isEqualToDateIgnoringTime
:[
NSDate
dateTomorrow
]];
}
-
(
BOOL
)
isYesterday
{
return
[
self
isEqualToDateIgnoringTime
:[
NSDate
dateYesterday
]];
}
// This hard codes the assumption that a week is 7 days
-
(
BOOL
)
isSameWeekAsDate
:
(
NSDate
*
)
aDate
{
NSDateComponents
*
components1
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
NSDateComponents
*
components2
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
aDate
];
// Must be same week. 12/31 and 1/1 will both be week "1" if they are in the same week
if
(
components1
.
weekOfMonth
!=
components2
.
weekOfMonth
)
return
NO
;
// Must have a time interval under 1 week. Thanks @aclark
return
(
fabs
([
self
timeIntervalSinceDate
:
aDate
])
<
D_WEEK
);
}
-
(
BOOL
)
isThisWeek
{
return
[
self
isSameWeekAsDate
:[
NSDate
date
]];
}
-
(
BOOL
)
isNextWeek
{
NSTimeInterval
aTimeInterval
=
[[
NSDate
date
]
timeIntervalSinceReferenceDate
]
+
D_WEEK
;
NSDate
*
newDate
=
[
NSDate
dateWithTimeIntervalSinceReferenceDate
:
aTimeInterval
];
return
[
self
isSameWeekAsDate
:
newDate
];
}
-
(
BOOL
)
isLastWeek
{
NSTimeInterval
aTimeInterval
=
[[
NSDate
date
]
timeIntervalSinceReferenceDate
]
-
D_WEEK
;
NSDate
*
newDate
=
[
NSDate
dateWithTimeIntervalSinceReferenceDate
:
aTimeInterval
];
return
[
self
isSameWeekAsDate
:
newDate
];
}
// Thanks, mspasov
-
(
BOOL
)
isSameMonthAsDate
:
(
NSDate
*
)
aDate
{
NSDateComponents
*
components1
=
[[
NSDate
currentCalendar
]
components
:
NSCalendarUnitYear
|
NSCalendarUnitMonth
fromDate
:
self
];
NSDateComponents
*
components2
=
[[
NSDate
currentCalendar
]
components
:
NSCalendarUnitYear
|
NSCalendarUnitMonth
fromDate
:
aDate
];
return
((
components1
.
month
==
components2
.
month
)
&&
(
components1
.
year
==
components2
.
year
));
}
-
(
BOOL
)
isThisMonth
{
return
[
self
isSameMonthAsDate
:[
NSDate
date
]];
}
// Thanks Marcin Krzyzanowski, also for adding/subtracting years and months
-
(
BOOL
)
isLastMonth
{
return
[
self
isSameMonthAsDate
:[[
NSDate
date
]
dateBySubtractingMonths
:
1
]];
}
-
(
BOOL
)
isNextMonth
{
return
[
self
isSameMonthAsDate
:[[
NSDate
date
]
dateByAddingMonths
:
1
]];
}
-
(
BOOL
)
isSameYearAsDate
:
(
NSDate
*
)
aDate
{
NSDateComponents
*
components1
=
[[
NSDate
currentCalendar
]
components
:
NSCalendarUnitYear
fromDate
:
self
];
NSDateComponents
*
components2
=
[[
NSDate
currentCalendar
]
components
:
NSCalendarUnitYear
fromDate
:
aDate
];
return
(
components1
.
year
==
components2
.
year
);
}
-
(
BOOL
)
isThisYear
{
// Thanks, baspellis
return
[
self
isSameYearAsDate
:[
NSDate
date
]];
}
-
(
BOOL
)
isNextYear
{
NSDateComponents
*
components1
=
[[
NSDate
currentCalendar
]
components
:
NSCalendarUnitYear
fromDate
:
self
];
NSDateComponents
*
components2
=
[[
NSDate
currentCalendar
]
components
:
NSCalendarUnitYear
fromDate
:[
NSDate
date
]];
return
(
components1
.
year
==
(
components2
.
year
+
1
));
}
-
(
BOOL
)
isLastYear
{
NSDateComponents
*
components1
=
[[
NSDate
currentCalendar
]
components
:
NSCalendarUnitYear
fromDate
:
self
];
NSDateComponents
*
components2
=
[[
NSDate
currentCalendar
]
components
:
NSCalendarUnitYear
fromDate
:[
NSDate
date
]];
return
(
components1
.
year
==
(
components2
.
year
-
1
));
}
-
(
BOOL
)
isEarlierThanDate
:
(
NSDate
*
)
aDate
{
return
([
self
compare
:
aDate
]
==
NSOrderedAscending
);
}
-
(
BOOL
)
isLaterThanDate
:
(
NSDate
*
)
aDate
{
return
([
self
compare
:
aDate
]
==
NSOrderedDescending
);
}
// Thanks, markrickert
-
(
BOOL
)
isInFuture
{
return
([
self
isLaterThanDate
:[
NSDate
date
]]);
}
// Thanks, markrickert
-
(
BOOL
)
isInPast
{
return
([
self
isEarlierThanDate
:[
NSDate
date
]]);
}
#pragma mark - Roles
-
(
BOOL
)
isTypicallyWeekend
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
NSCalendarUnitWeekday
fromDate
:
self
];
if
((
components
.
weekday
==
1
)
||
(
components
.
weekday
==
7
))
return
YES
;
return
NO
;
}
-
(
BOOL
)
isTypicallyWorkday
{
return
!
[
self
isTypicallyWeekend
];
}
#pragma mark - Adjusting Dates
// Thaks, rsjohnson
-
(
NSDate
*
)
dateByAddingYears
:
(
NSInteger
)
dYears
{
NSDateComponents
*
dateComponents
=
[[
NSDateComponents
alloc
]
init
];
[
dateComponents
setYear
:
dYears
];
NSDate
*
newDate
=
[[
NSCalendar
currentCalendar
]
dateByAddingComponents
:
dateComponents
toDate
:
self
options
:
0
];
return
newDate
;
}
-
(
NSDate
*
)
dateBySubtractingYears
:
(
NSInteger
)
dYears
{
return
[
self
dateByAddingYears
:
-
dYears
];
}
-
(
NSDate
*
)
dateByAddingMonths
:
(
NSInteger
)
dMonths
{
NSDateComponents
*
dateComponents
=
[[
NSDateComponents
alloc
]
init
];
[
dateComponents
setMonth
:
dMonths
];
NSDate
*
newDate
=
[[
NSCalendar
currentCalendar
]
dateByAddingComponents
:
dateComponents
toDate
:
self
options
:
0
];
return
newDate
;
}
-
(
NSDate
*
)
dateBySubtractingMonths
:
(
NSInteger
)
dMonths
{
return
[
self
dateByAddingMonths
:
-
dMonths
];
}
// Courtesy of dedan who mentions issues with Daylight Savings
-
(
NSDate
*
)
dateByAddingDays
:
(
NSInteger
)
dDays
{
NSDateComponents
*
dateComponents
=
[[
NSDateComponents
alloc
]
init
];
[
dateComponents
setDay
:
dDays
];
NSDate
*
newDate
=
[[
NSCalendar
currentCalendar
]
dateByAddingComponents
:
dateComponents
toDate
:
self
options
:
0
];
return
newDate
;
}
-
(
NSDate
*
)
dateBySubtractingDays
:
(
NSInteger
)
dDays
{
return
[
self
dateByAddingDays
:
(
dDays
*
-
1
)];
}
-
(
NSDate
*
)
dateByAddingHours
:
(
NSInteger
)
dHours
{
NSTimeInterval
aTimeInterval
=
[
self
timeIntervalSinceReferenceDate
]
+
D_HOUR
*
dHours
;
NSDate
*
newDate
=
[
NSDate
dateWithTimeIntervalSinceReferenceDate
:
aTimeInterval
];
return
newDate
;
}
-
(
NSDate
*
)
dateBySubtractingHours
:
(
NSInteger
)
dHours
{
return
[
self
dateByAddingHours
:
(
dHours
*
-
1
)];
}
-
(
NSDate
*
)
dateByAddingMinutes
:
(
NSInteger
)
dMinutes
{
NSTimeInterval
aTimeInterval
=
[
self
timeIntervalSinceReferenceDate
]
+
D_MINUTE
*
dMinutes
;
NSDate
*
newDate
=
[
NSDate
dateWithTimeIntervalSinceReferenceDate
:
aTimeInterval
];
return
newDate
;
}
-
(
NSDate
*
)
dateBySubtractingMinutes
:
(
NSInteger
)
dMinutes
{
return
[
self
dateByAddingMinutes
:
(
dMinutes
*
-
1
)];
}
-
(
NSDateComponents
*
)
componentsWithOffsetFromDate
:
(
NSDate
*
)
aDate
{
NSDateComponents
*
dTime
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
aDate
toDate
:
self
options
:
0
];
return
dTime
;
}
#pragma mark - Extremes
-
(
NSDate
*
)
dateAtStartOfDay
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
components
.
hour
=
0
;
components
.
minute
=
0
;
components
.
second
=
0
;
return
[[
NSDate
currentCalendar
]
dateFromComponents
:
components
];
}
// Thanks gsempe & mteece
-
(
NSDate
*
)
dateAtEndOfDay
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
components
.
hour
=
23
;
// Thanks Aleksey Kononov
components
.
minute
=
59
;
components
.
second
=
59
;
return
[[
NSDate
currentCalendar
]
dateFromComponents
:
components
];
}
#pragma mark - Retrieving Intervals
-
(
NSInteger
)
minutesAfterDate
:
(
NSDate
*
)
aDate
{
NSTimeInterval
ti
=
[
self
timeIntervalSinceDate
:
aDate
];
return
(
NSInteger
)
(
ti
/
D_MINUTE
);
}
-
(
NSInteger
)
minutesBeforeDate
:
(
NSDate
*
)
aDate
{
NSTimeInterval
ti
=
[
aDate
timeIntervalSinceDate
:
self
];
return
(
NSInteger
)
(
ti
/
D_MINUTE
);
}
-
(
NSInteger
)
hoursAfterDate
:
(
NSDate
*
)
aDate
{
NSTimeInterval
ti
=
[
self
timeIntervalSinceDate
:
aDate
];
return
(
NSInteger
)
(
ti
/
D_HOUR
);
}
-
(
NSInteger
)
hoursBeforeDate
:
(
NSDate
*
)
aDate
{
NSTimeInterval
ti
=
[
aDate
timeIntervalSinceDate
:
self
];
return
(
NSInteger
)
(
ti
/
D_HOUR
);
}
-
(
NSInteger
)
daysAfterDate
:
(
NSDate
*
)
aDate
{
NSTimeInterval
ti
=
[
self
timeIntervalSinceDate
:
aDate
];
return
(
NSInteger
)
(
ti
/
D_DAY
);
}
-
(
NSInteger
)
daysBeforeDate
:
(
NSDate
*
)
aDate
{
NSTimeInterval
ti
=
[
aDate
timeIntervalSinceDate
:
self
];
return
(
NSInteger
)
(
ti
/
D_DAY
);
}
// Thanks, dmitrydims
// I have not yet thoroughly tested this
-
(
NSInteger
)
distanceInDaysToDate
:
(
NSDate
*
)
anotherDate
{
NSCalendar
*
gregorianCalendar
=
[[
NSCalendar
alloc
]
initWithCalendarIdentifier
:
NSCalendarIdentifierGregorian
];
NSDateComponents
*
components
=
[
gregorianCalendar
components
:
NSCalendarUnitDay
fromDate
:
self
toDate
:
anotherDate
options
:
0
];
return
components
.
day
;
}
#pragma mark - Decomposing Dates
-
(
NSInteger
)
nearestHour
{
NSTimeInterval
aTimeInterval
=
[[
NSDate
date
]
timeIntervalSinceReferenceDate
]
+
D_MINUTE
*
30
;
NSDate
*
newDate
=
[
NSDate
dateWithTimeIntervalSinceReferenceDate
:
aTimeInterval
];
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
NSCalendarUnitHour
fromDate
:
newDate
];
return
components
.
hour
;
}
-
(
NSInteger
)
hour
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
return
components
.
hour
;
}
-
(
NSInteger
)
minute
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
return
components
.
minute
;
}
-
(
NSInteger
)
seconds
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
return
components
.
second
;
}
-
(
NSInteger
)
day
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
return
components
.
day
;
}
-
(
NSInteger
)
month
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
return
components
.
month
;
}
-
(
NSInteger
)
week
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
return
components
.
weekOfMonth
;
}
-
(
NSInteger
)
weekday
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
return
components
.
weekday
;
}
-
(
NSInteger
)
nthWeekday
// e.g. 2nd Tuesday of the month is 2
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
return
components
.
weekdayOrdinal
;
}
-
(
NSInteger
)
year
{
NSDateComponents
*
components
=
[[
NSDate
currentCalendar
]
components
:
componentFlags
fromDate
:
self
];
return
components
.
year
;
}
+
(
NSDate
*
)
date
:
(
NSString
*
)
datestr
WithFormat
:
(
NSString
*
)
format
{
NSDateFormatter
*
dateFormatter
=
[[
NSDateFormatter
alloc
]
init
];
[
dateFormatter
setLocale
:[
NSLocale
currentLocale
]];
[
dateFormatter
setTimeZone
:[
NSTimeZone
localTimeZone
]];
[
dateFormatter
setDateFormat
:
format
];
NSDate
*
date
=
[
dateFormatter
dateFromString
:
datestr
];
#if ! __has_feature(objc_arc)
[
dateFormatter
release
];
#endif
return
date
;
}
-
(
NSDate
*
)
dateWithYMD
{
NSDateFormatter
*
fmt
=
[[
NSDateFormatter
alloc
]
init
];
fmt
.
dateFormat
=
@"yyyy-MM-dd"
;
NSString
*
selfStr
=
[
fmt
stringFromDate
:
self
];
return
[
fmt
dateFromString
:
selfStr
];
}
-
(
NSDate
*
)
dateWithFormatter
:
(
NSString
*
)
formatter
{
NSDateFormatter
*
fmt
=
[[
NSDateFormatter
alloc
]
init
];
fmt
.
dateFormat
=
formatter
;
NSString
*
selfStr
=
[
fmt
stringFromDate
:
self
];
return
[
fmt
dateFromString
:
selfStr
];
}
@end
DreamSleep/DreamSleep/Vendors/WSDaePickerView/WSDatePickerView.h
0 → 100755
查看文件 @
fe09f1c
//
// WSDatePickerView.h
// WSDatePicker
//
// Created by iMac on 17/2/23.
// Copyright © 2017年 zws. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "NSDate+Extension.h"
/**
* 弹出日期类型
*/
typedef
enum
{
DateStyleShowYearMonthDayHourMinute
=
0
,
// 年月日时分
DateStyleShowMonthDayHourMinute
,
// 月日时分
DateStyleShowYearMonthDay
,
// 年月日
DateStyleShowMonthDay
,
// 月日
DateStyleShowHourMinute
// 时分
}
WSDateStyle
;
@interface
WSDatePickerView
:
UIView
/**
* 滚轮日期颜色(默认黑色)
*/
@property
(
nonatomic
,
strong
)
UIColor
*
datePickerColor
;
/**
* 选中日期颜色
*/
@property
(
nonatomic
,
strong
)
UIColor
*
selectedPickerColor
;
/**
* 选中分割线颜色
*/
@property
(
nonatomic
,
strong
)
UIColor
*
selectedLineColor
;
/**
* 限制最小时间(默认0) datePicker小于最小日期则滚动回最小限制日期
*/
@property
(
nonatomic
,
retain
)
NSDate
*
minLimitDate
;
/**
* 限制最大时间(默认2099)datePicker大于最大日期则滚动回最大限制日期
*/
@property
(
nonatomic
,
retain
)
NSDate
*
maxLimitDate
;
/**
默认滚动到当前时间
*/
-
(
instancetype
)
initWithDateStyle
:(
WSDateStyle
)
datePickerStyle
CompleteBlock
:(
void
(
^
)(
NSDate
*
))
completeBlock
;
/**
滚动到指定的的日期
*/
-
(
instancetype
)
initWithDateStyle
:(
WSDateStyle
)
datePickerStyle
scrollToDate
:(
NSDate
*
)
scrollToDate
CompleteBlock
:(
void
(
^
)(
NSDate
*
))
completeBlock
;
/**
显示
*/
-
(
void
)
show
;
@end
DreamSleep/DreamSleep/Vendors/WSDaePickerView/WSDatePickerView.m
0 → 100755
查看文件 @
fe09f1c
//
// WSDatePickerView.m
// WSDatePicker
//
// Created by iMac on 17/2/23.
// Copyright © 2017年 zws. All rights reserved.
//
#define MINYEAR 0
#define MAXYEAR 2099
#define kPickerSize self.datePicker.frame.size
typedef
void
(
^
doneBlock
)(
NSDate
*
);
#import "WSDatePickerView.h"
@interface
WSDatePickerView
()
<
UIPickerViewDelegate
,
UIPickerViewDataSource
,
UIGestureRecognizerDelegate
>
{
// 日期存储数组
NSMutableArray
*
_yearArray
;
NSMutableArray
*
_monthArray
;
NSMutableArray
*
_dayArray
;
NSMutableArray
*
_hourArray
;
NSMutableArray
*
_minuteArray
;
NSString
*
_dateFormatter
;
// 记录位置
NSInteger
yearIndex
;
NSInteger
monthIndex
;
NSInteger
dayIndex
;
NSInteger
hourIndex
;
NSInteger
minuteIndex
;
NSInteger
preRow
;
NSDate
*
_startDate
;
NSDate
*
_selectedDate
;
}
@property
(
weak
,
nonatomic
)
IBOutlet
UIView
*
buttomView
;
@property
(
nonatomic
,
strong
)
UIPickerView
*
datePicker
;
// 滚到指定日期
@property
(
nonatomic
,
strong
)
NSDate
*
scrollToDate
;
@property
(
nonatomic
,
strong
)
doneBlock
doneBlock
;
@property
(
nonatomic
,
assign
)
WSDateStyle
datePickerStyle
;
@end
@implementation
WSDatePickerView
#pragma mark - 初始化
-
(
instancetype
)
initWithDateStyle
:(
WSDateStyle
)
datePickerStyle
CompleteBlock
:(
void
(
^
)(
NSDate
*
))
completeBlock
{
if
(
self
=
[
super
init
])
{
self
=
[[[
NSBundle
mainBundle
]
loadNibNamed
:
NSStringFromClass
([
self
class
])
owner
:
self
options
:
nil
]
lastObject
];
self
.
datePickerStyle
=
datePickerStyle
;
switch
(
datePickerStyle
)
{
case
DateStyleShowYearMonthDayHourMinute
:
_dateFormatter
=
@"yyyy-MM-dd HH:mm"
;
break
;
case
DateStyleShowMonthDayHourMinute
:
_dateFormatter
=
@"yyyy-MM-dd HH:mm"
;
break
;
case
DateStyleShowYearMonthDay
:
_dateFormatter
=
@"yyyy-MM-dd"
;
break
;
case
DateStyleShowMonthDay
:
_dateFormatter
=
@"yyyy-MM-dd"
;
break
;
case
DateStyleShowHourMinute
:
_dateFormatter
=
@"HH:mm"
;
break
;
default:
_dateFormatter
=
@"yyyy-MM-dd HH:mm"
;
break
;
}
[
self
setupUI
];
[
self
defaultConfig
];
if
(
completeBlock
)
{
self
.
doneBlock
=
^
(
NSDate
*
selectDate
)
{
completeBlock
(
selectDate
);
};
}
}
return
self
;
}
-
(
instancetype
)
initWithDateStyle
:(
WSDateStyle
)
datePickerStyle
scrollToDate
:(
NSDate
*
)
scrollToDate
CompleteBlock
:(
void
(
^
)(
NSDate
*
))
completeBlock
{
if
(
self
=
[
super
init
])
{
self
=
[[[
NSBundle
mainBundle
]
loadNibNamed
:
NSStringFromClass
([
self
class
])
owner
:
self
options
:
nil
]
lastObject
];
self
.
datePickerStyle
=
datePickerStyle
;
self
.
scrollToDate
=
scrollToDate
;
switch
(
datePickerStyle
)
{
case
DateStyleShowYearMonthDayHourMinute
:
_dateFormatter
=
@"yyyy-MM-dd HH:mm"
;
break
;
case
DateStyleShowMonthDayHourMinute
:
_dateFormatter
=
@"yyyy-MM-dd HH:mm"
;
break
;
case
DateStyleShowYearMonthDay
:
_dateFormatter
=
@"yyyy-MM-dd"
;
break
;
case
DateStyleShowMonthDay
:
_dateFormatter
=
@"yyyy-MM-dd"
;
break
;
case
DateStyleShowHourMinute
:
_dateFormatter
=
@"HH:mm"
;
break
;
default:
_dateFormatter
=
@"yyyy-MM-dd HH:mm"
;
break
;
}
[
self
setupUI
];
[
self
defaultConfig
];
if
(
completeBlock
)
{
self
.
doneBlock
=
^
(
NSDate
*
selectDate
)
{
completeBlock
(
selectDate
);
};
}
}
return
self
;
}
-
(
void
)
setupUI
{
self
.
frame
=
CGRectMake
(
0
,
0
,
kScreenWidth
,
kScreenHeight
);
self
.
dk_backgroundColorPicker
=
DKColorPickerWithColors
(
ColorFromHex
(
0x6F7587
),
DSClearColor
,
DSWhite
);
self
.
backgroundColor
=
[
self
.
backgroundColor
colorWithAlphaComponent
:
0
.
6
];
[[
UIApplication
sharedApplication
].
keyWindow
bringSubviewToFront
:
self
];
self
.
buttomView
.
dk_backgroundColorPicker
=
DKColorPickerWithKey
(
TabBarBG
);
[
self
.
buttomView
cornerRadius
:
20
];
[
self
.
buttomView
addSubview
:
self
.
datePicker
];
UILabel
*
titleLab
=
[
UILabel
dkLabWithText
:
@"生日"
font
:
BoldFont
(
16
)];
titleLab
.
textAlignment
=
NSTextAlignmentCenter
;
[
self
.
buttomView
addSubview
:
titleLab
];
UIButton
*
cancel
=
[
UIButton
dkBtnTitle
:
@"取消"
font
:
SysFont
(
15
)];
[
cancel
addTarget
:
self
action
:
@selector
(
dismiss
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
self
.
buttomView
addSubview
:
cancel
];
UIButton
*
sureBtn
=
[
UIButton
btnWithTitle
:
@"确定"
titleColor
:
BrandColor
font
:
BoldFont
(
15
)];
[
sureBtn
addTarget
:
self
action
:
@selector
(
sureAction
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
self
.
buttomView
addSubview
:
sureBtn
];
UIView
*
line
=
[
UIView
new
];
line
.
dk_backgroundColorPicker
=
DKColorPickerWithColors
(
DivideLineColor
,
DSWhite
,
DSWhite
);
[
self
.
buttomView
addSubview
:
line
];
[
self
.
buttomView
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
center
.
equalTo
(
self
);
make
.
size
.
mas_equalTo
(
CGSizeMake
(
280
,
236
));
}];
[
titleLab
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
centerX
.
equalTo
(
self
.
buttomView
);
make
.
top
.
equalTo
(
self
.
buttomView
).
offset
(
20
);
make
.
left
.
right
.
equalTo
(
self
.
buttomView
);
}];
[
self
.
datePicker
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
top
.
equalTo
(
titleLab
.
mas_bottom
).
offset
(
20
);
make
.
center
.
equalTo
(
self
.
buttomView
);
make
.
width
.
equalTo
(
self
.
buttomView
);
make
.
bottom
.
equalTo
(
cancel
.
mas_top
);
}];
[
cancel
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
height
.
equalTo
(
@64
);
make
.
left
.
bottom
.
equalTo
(
self
.
buttomView
);
}];
[
sureBtn
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
size
.
equalTo
(
cancel
);
make
.
right
.
bottom
.
equalTo
(
self
.
buttomView
);
make
.
left
.
equalTo
(
cancel
.
mas_right
);
}];
[
line
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
centerY
.
equalTo
(
cancel
);
make
.
centerX
.
equalTo
(
self
.
buttomView
);
make
.
top
.
equalTo
(
cancel
).
offset
(
12
);
make
.
bottom
.
equalTo
(
cancel
).
offset
(
-
12
);
make
.
width
.
equalTo
(
@1
);
}];
// 点击背景是否影藏
UITapGestureRecognizer
*
tap
=
[[
UITapGestureRecognizer
alloc
]
initWithTarget
:
self
action
:
@selector
(
dismiss
)];
tap
.
delegate
=
self
;
[
self
addGestureRecognizer
:
tap
];
}
-
(
void
)
defaultConfig
{
if
(
!
_scrollToDate
)
{
_scrollToDate
=
[
NSDate
date
];
}
// 循环滚动时需要用到
preRow
=
(
self
.
scrollToDate
.
year
-
MINYEAR
)
*
12
+
self
.
scrollToDate
.
month
-
1
;
// 设置年月日时分数据
_yearArray
=
[
self
setArray
:
_yearArray
];
_monthArray
=
[
self
setArray
:
_monthArray
];
_dayArray
=
[
self
setArray
:
_dayArray
];
_hourArray
=
[
self
setArray
:
_hourArray
];
_minuteArray
=
[
self
setArray
:
_minuteArray
];
for
(
int
i
=
0
;
i
<
60
;
i
++
)
{
NSString
*
num
=
[
NSString
stringWithFormat
:
@"%d"
,
i
];
if
(
0
<
i
&&
i
<=
12
)
{
[
_monthArray
addObject
:
num
];
}
if
(
i
<
24
)
{
[
_hourArray
addObject
:
num
];
}
[
_minuteArray
addObject
:
num
];
}
for
(
NSInteger
i
=
MINYEAR
;
i
<=
MAXYEAR
;
i
++
)
{
NSString
*
num
=
[
NSString
stringWithFormat
:
@"%ld"
,
(
long
)
i
];
[
_yearArray
addObject
:
num
];
}
// 最大最小限制
if
(
!
self
.
maxLimitDate
)
{
self
.
maxLimitDate
=
[
NSDate
date
:
@"2099-12-31 23:59"
WithFormat
:
@"yyyy-MM-dd HH:mm"
];
}
// 最小限制
if
(
!
self
.
minLimitDate
)
{
self
.
minLimitDate
=
[
NSDate
date
:
@"0000-01-01 00:00"
WithFormat
:
@"yyyy-MM-dd HH:mm"
];
}
}
#pragma mark - UIPickerViewDelegate && UIPickerViewDataSource
-
(
NSInteger
)
numberOfComponentsInPickerView
:
(
UIPickerView
*
)
pickerView
{
switch
(
self
.
datePickerStyle
)
{
case
DateStyleShowYearMonthDayHourMinute
:
return
5
;
case
DateStyleShowMonthDayHourMinute
:
return
4
;
case
DateStyleShowYearMonthDay
:
return
3
;
case
DateStyleShowMonthDay
:
return
2
;
case
DateStyleShowHourMinute
:
return
2
;
default
:
return
0
;
}
}
-
(
NSInteger
)
pickerView
:
(
UIPickerView
*
)
pickerView
numberOfRowsInComponent
:
(
NSInteger
)
component
{
NSArray
*
numberArr
=
[
self
getNumberOfRowsInComponent
];
return
[
numberArr
[
component
]
integerValue
];
}
-
(
NSArray
*
)
getNumberOfRowsInComponent
{
NSInteger
yearNum
=
_yearArray
.
count
;
NSInteger
monthNum
=
_monthArray
.
count
;
NSInteger
dayNum
=
[
self
DaysfromYear
:[
_yearArray
[
yearIndex
]
integerValue
]
andMonth
:[
_monthArray
[
monthIndex
]
integerValue
]];
NSInteger
hourNum
=
_hourArray
.
count
;
NSInteger
minuteNUm
=
_minuteArray
.
count
;
NSInteger
timeInterval
=
MAXYEAR
-
MINYEAR
;
switch
(
self
.
datePickerStyle
)
{
case
DateStyleShowYearMonthDayHourMinute
:
return
@[
@
(
yearNum
),
@
(
monthNum
),
@
(
dayNum
),
@
(
hourNum
),
@
(
minuteNUm
)];
break
;
case
DateStyleShowMonthDayHourMinute
:
return
@[
@
(
monthNum
*
timeInterval
),
@
(
dayNum
),
@
(
hourNum
),
@
(
minuteNUm
)];
break
;
case
DateStyleShowYearMonthDay
:
return
@[
@
(
yearNum
),
@
(
monthNum
),
@
(
dayNum
)];
break
;
case
DateStyleShowMonthDay
:
return
@[
@
(
monthNum
*
timeInterval
),
@
(
dayNum
),
@
(
hourNum
)];
break
;
case
DateStyleShowHourMinute
:
return
@[
@
(
hourNum
),
@
(
minuteNUm
)];
break
;
default
:
return
@[];
break
;
}
}
-
(
CGFloat
)
pickerView
:
(
UIPickerView
*
)
pickerView
rowHeightForComponent
:
(
NSInteger
)
component
{
return
40
;
}
-
(
UIView
*
)
pickerView
:
(
UIPickerView
*
)
pickerView
viewForRow
:
(
NSInteger
)
row
forComponent
:
(
NSInteger
)
component
reusingView
:
(
UIView
*
)
view
{
if
(
@available
(
iOS
14
.
0
,
*
))
{
pickerView
.
subviews
[
1
].
backgroundColor
=
DSClearColor
;
}
UILabel
*
customLabel
=
(
UILabel
*
)
view
;
if
(
!
customLabel
)
{
customLabel
=
[[
UILabel
alloc
]
init
];
customLabel
.
textAlignment
=
NSTextAlignmentCenter
;
[
customLabel
setFont
:[
UIFont
systemFontOfSize
:
18
]];
}
customLabel
.
textColor
=
BrandColor
;
NSString
*
title
;
for
(
UIView
*
speartorView
in
self
.
datePicker
.
subviews
)
{
if
(
speartorView
.
frame
.
size
.
height
<
1
)
{
// 取出分割线view
speartorView
.
backgroundColor
=
ColorFromHex
(
0x51B79A
);
}
}
switch
(
self
.
datePickerStyle
)
{
case
DateStyleShowYearMonthDayHourMinute
:
if
(
component
==
0
)
{
title
=
_yearArray
[
row
];
}
if
(
component
==
1
)
{
title
=
_monthArray
[
row
];
}
if
(
component
==
2
)
{
title
=
_dayArray
[
row
];
}
if
(
component
==
3
)
{
title
=
_hourArray
[
row
];
}
if
(
component
==
4
)
{
title
=
_minuteArray
[
row
];
}
break
;
case
DateStyleShowYearMonthDay
:
if
(
component
==
0
)
{
// 年份
title
=
_yearArray
[
row
];
if
(
yearIndex
==
row
)
{
customLabel
.
font
=
BoldFont
(
16
);
}
else
{
customLabel
.
font
=
BoldFont
(
14
);
}
}
if
(
component
==
1
)
{
// 月份
title
=
_monthArray
[
row
];
title
=
title
.
length
==
2
?
title
:
[
NSString
stringWithFormat
:
@"0%@"
,
title
];
if
(
monthIndex
==
row
)
{
customLabel
.
font
=
BoldFont
(
16
);
}
else
{
customLabel
.
font
=
BoldFont
(
14
);
}
}
if
(
component
==
2
)
{
// 日
title
=
_dayArray
[
row
];
title
=
title
.
length
==
2
?
title
:
[
NSString
stringWithFormat
:
@"0%@"
,
title
];
if
(
dayIndex
==
row
)
{
customLabel
.
font
=
BoldFont
(
16
);
}
else
{
customLabel
.
font
=
BoldFont
(
14
);
}
}
break
;
case
DateStyleShowMonthDayHourMinute
:
if
(
component
==
0
)
{
title
=
_monthArray
[
row
%
12
];
}
if
(
component
==
1
)
{
title
=
_dayArray
[
row
];
}
if
(
component
==
2
)
{
title
=
_hourArray
[
row
];
}
if
(
component
==
3
)
{
title
=
_minuteArray
[
row
];
}
break
;
case
DateStyleShowMonthDay
:
if
(
component
==
0
)
{
title
=
_monthArray
[
row
%
12
];
}
if
(
component
==
1
)
{
title
=
_dayArray
[
row
];
}
break
;
case
DateStyleShowHourMinute
:
if
(
component
==
0
)
{
title
=
_hourArray
[
row
];
}
if
(
component
==
1
)
{
title
=
_minuteArray
[
row
];
}
break
;
default
:
title
=
@""
;
break
;
}
customLabel
.
text
=
title
;
return
customLabel
;
}
-
(
void
)
pickerView
:
(
UIPickerView
*
)
pickerView
didSelectRow
:
(
NSInteger
)
row
inComponent
:
(
NSInteger
)
component
{
switch
(
self
.
datePickerStyle
)
{
case
DateStyleShowYearMonthDayHourMinute
:
{
if
(
component
==
0
)
{
yearIndex
=
row
;
}
if
(
component
==
1
)
{
monthIndex
=
row
;
}
if
(
component
==
2
)
{
dayIndex
=
row
;
}
if
(
component
==
3
)
{
hourIndex
=
row
;
}
if
(
component
==
4
)
{
minuteIndex
=
row
;
}
if
(
component
==
0
||
component
==
1
)
{
[
self
DaysfromYear
:[
_yearArray
[
yearIndex
]
integerValue
]
andMonth
:[
_monthArray
[
monthIndex
]
integerValue
]];
if
(
_dayArray
.
count
-
1
<
dayIndex
)
{
dayIndex
=
_dayArray
.
count
-
1
;
}
}
}
break
;
case
DateStyleShowYearMonthDay
:
{
if
(
component
==
0
)
{
yearIndex
=
row
;
}
if
(
component
==
1
)
{
monthIndex
=
row
;
}
if
(
component
==
2
)
{
dayIndex
=
row
;
}
if
(
component
==
0
||
component
==
1
)
{
[
self
DaysfromYear
:[
_yearArray
[
yearIndex
]
integerValue
]
andMonth
:[
_monthArray
[
monthIndex
]
integerValue
]];
if
(
_dayArray
.
count
-
1
<
dayIndex
)
{
dayIndex
=
_dayArray
.
count
-
1
;
}
}
}
break
;
case
DateStyleShowMonthDayHourMinute
:
{
if
(
component
==
1
)
{
dayIndex
=
row
;
}
if
(
component
==
2
)
{
hourIndex
=
row
;
}
if
(
component
==
3
)
{
minuteIndex
=
row
;
}
if
(
component
==
0
)
{
[
self
yearChange
:
row
];
[
self
DaysfromYear
:[
_yearArray
[
yearIndex
]
integerValue
]
andMonth
:[
_monthArray
[
monthIndex
]
integerValue
]];
if
(
_dayArray
.
count
-
1
<
dayIndex
)
{
dayIndex
=
_dayArray
.
count
-
1
;
}
}
[
self
DaysfromYear
:[
_yearArray
[
yearIndex
]
integerValue
]
andMonth
:[
_monthArray
[
monthIndex
]
integerValue
]];
}
break
;
case
DateStyleShowMonthDay
:
{
if
(
component
==
1
)
{
dayIndex
=
row
;
}
if
(
component
==
0
)
{
[
self
yearChange
:
row
];
[
self
DaysfromYear
:[
_yearArray
[
yearIndex
]
integerValue
]
andMonth
:[
_monthArray
[
monthIndex
]
integerValue
]];
if
(
_dayArray
.
count
-
1
<
dayIndex
)
{
dayIndex
=
_dayArray
.
count
-
1
;
}
}
[
self
DaysfromYear
:[
_yearArray
[
yearIndex
]
integerValue
]
andMonth
:[
_monthArray
[
monthIndex
]
integerValue
]];
}
break
;
case
DateStyleShowHourMinute
:
{
if
(
component
==
0
)
{
hourIndex
=
row
;
}
if
(
component
==
1
)
{
minuteIndex
=
row
;
}
}
break
;
default
:
break
;
}
[
pickerView
reloadAllComponents
];
NSString
*
dateStr
=
[
NSString
stringWithFormat
:
@"%@-%@-%@ %@:%@"
,
_yearArray
[
yearIndex
],
_monthArray
[
monthIndex
],
_dayArray
[
dayIndex
],
_hourArray
[
hourIndex
],
_minuteArray
[
minuteIndex
]];
self
.
scrollToDate
=
[[
NSDate
date
:
dateStr
WithFormat
:
@"yyyy-MM-dd HH:mm"
]
dateWithFormatter
:
_dateFormatter
];
if
([
self
.
scrollToDate
compare
:
self
.
minLimitDate
]
==
NSOrderedAscending
)
{
self
.
scrollToDate
=
self
.
minLimitDate
;
[
self
getNowDate
:
self
.
minLimitDate
animated
:
YES
];
}
else
if
([
self
.
scrollToDate
compare
:
self
.
maxLimitDate
]
==
NSOrderedDescending
)
{
self
.
scrollToDate
=
self
.
maxLimitDate
;
[
self
getNowDate
:
self
.
maxLimitDate
animated
:
YES
];
}
_startDate
=
self
.
scrollToDate
;
_selectedDate
=
[
self
.
scrollToDate
dateWithFormatter
:
_dateFormatter
];
}
#pragma mark - UIGestureRecognizerDelegate
-
(
BOOL
)
gestureRecognizer
:
(
UIGestureRecognizer
*
)
gestureRecognizer
shouldReceiveTouch
:
(
UITouch
*
)
touch
{
if
(
[
touch
.
view
isDescendantOfView
:
self
.
buttomView
])
{
return
NO
;
}
return
YES
;
}
#pragma mark - Action
-
(
void
)
show
{
[[
UIApplication
sharedApplication
].
keyWindow
addSubview
:
self
];
}
-
(
void
)
dismiss
{
[
self
.
subviews
makeObjectsPerformSelector
:
@selector
(
removeFromSuperview
)];
[
self
removeFromSuperview
];
}
-
(
void
)
sureAction
{
[
self
dismiss
];
if
(
self
.
doneBlock
)
{
self
.
doneBlock
((
_selectedDate
?
_selectedDate
:
_scrollToDate
));
}
}
#pragma mark - tools
#pragma mark - 年份状态变化
-
(
void
)
yearChange
:
(
NSInteger
)
row
{
monthIndex
=
row
%
12
;
if
(
row
-
preRow
<
12
&&
row
-
preRow
>
0
&&
[
_monthArray
[
monthIndex
]
integerValue
]
<
[
_monthArray
[
preRow
%
12
]
integerValue
])
{
yearIndex
++
;
}
else
if
(
preRow
-
row
<
12
&&
preRow
-
row
>
0
&&
[
_monthArray
[
monthIndex
]
integerValue
]
>
[
_monthArray
[
preRow
%
12
]
integerValue
])
{
yearIndex
--
;
}
else
{
NSInteger
interval
=
(
row
-
preRow
)
/
12
;
yearIndex
+=
interval
;
}
preRow
=
row
;
}
// 通过年月求每月天数
-
(
NSInteger
)
DaysfromYear
:
(
NSInteger
)
year
andMonth
:
(
NSInteger
)
month
{
NSInteger
num_year
=
year
;
NSInteger
num_month
=
month
;
BOOL
isrunNian
=
(
num_year
%
4
==
0
)
?
((
num_year
%
100
==
0
)
?
((
num_year
%
400
==
0
)
?
YES
:
NO
)
:
YES
)
:
NO
;
switch
(
num_month
)
{
case
1
:
case
3
:
case
5
:
case
7
:
case
8
:
case
10
:
case
12
:
{
[
self
setdayArray
:
31
];
return
31
;
}
case
4
:
case
6
:
case
9
:
case
11
:
{
[
self
setdayArray
:
30
];
return
30
;
}
case
2
:
{
if
(
isrunNian
)
{
[
self
setdayArray
:
29
];
return
29
;
}
else
{
[
self
setdayArray
:
28
];
return
28
;
}
}
default
:
break
;
}
return
0
;
}
// 设置每月的天数数组
-
(
void
)
setdayArray
:
(
NSInteger
)
num
{
[
_dayArray
removeAllObjects
];
for
(
int
i
=
1
;
i
<=
num
;
i
++
)
{
[
_dayArray
addObject
:[
NSString
stringWithFormat
:
@"%d"
,
i
]];
}
}
// 滚动到指定的时间位置
-
(
void
)
getNowDate
:
(
NSDate
*
)
date
animated
:
(
BOOL
)
animated
{
if
(
!
date
)
{
date
=
[
NSDate
date
];
}
[
self
DaysfromYear
:
date
.
year
andMonth
:
date
.
month
];
yearIndex
=
date
.
year
-
MINYEAR
;
monthIndex
=
date
.
month
-
1
;
dayIndex
=
date
.
day
-
1
;
hourIndex
=
date
.
hour
;
minuteIndex
=
date
.
minute
;
// 循环滚动时需要用到
preRow
=
(
self
.
scrollToDate
.
year
-
MINYEAR
)
*
12
+
self
.
scrollToDate
.
month
-
1
;
NSArray
*
indexArray
;
if
(
self
.
datePickerStyle
==
DateStyleShowYearMonthDayHourMinute
)
indexArray
=
@[
@
(
yearIndex
),
@
(
monthIndex
),
@
(
dayIndex
),
@
(
hourIndex
),
@
(
minuteIndex
)];
if
(
self
.
datePickerStyle
==
DateStyleShowYearMonthDay
)
indexArray
=
@[
@
(
yearIndex
),
@
(
monthIndex
),
@
(
dayIndex
)];
if
(
self
.
datePickerStyle
==
DateStyleShowMonthDayHourMinute
)
indexArray
=
@[
@
(
monthIndex
),
@
(
dayIndex
),
@
(
hourIndex
),
@
(
minuteIndex
)];
if
(
self
.
datePickerStyle
==
DateStyleShowMonthDay
)
indexArray
=
@[
@
(
monthIndex
),
@
(
dayIndex
)];
if
(
self
.
datePickerStyle
==
DateStyleShowHourMinute
)
indexArray
=
@[
@
(
hourIndex
),
@
(
minuteIndex
)];
[
self
.
datePicker
reloadAllComponents
];
for
(
int
i
=
0
;
i
<
indexArray
.
count
;
i
++
)
{
if
((
self
.
datePickerStyle
==
DateStyleShowMonthDayHourMinute
||
self
.
datePickerStyle
==
DateStyleShowMonthDay
)
&&
i
==
0
)
{
NSInteger
mIndex
=
[
indexArray
[
i
]
integerValue
]
+
(
12
*
(
self
.
scrollToDate
.
year
-
MINYEAR
));
[
self
.
datePicker
selectRow
:
mIndex
inComponent
:
i
animated
:
animated
];
}
else
{
[
self
.
datePicker
selectRow
:[
indexArray
[
i
]
integerValue
]
inComponent
:
i
animated
:
animated
];
}
}
}
#pragma mark - getter / setter
-
(
NSMutableArray
*
)
setArray
:
(
id
)
mutableArray
{
if
(
mutableArray
)
[
mutableArray
removeAllObjects
];
else
mutableArray
=
[
NSMutableArray
array
];
return
mutableArray
;
}
-
(
UIPickerView
*
)
datePicker
{
if
(
!
_datePicker
)
{
_datePicker
=
[
UIPickerView
new
];
_datePicker
.
delegate
=
self
;
_datePicker
.
dataSource
=
self
;
_datePicker
.
showsSelectionIndicator
=
YES
;
}
return
_datePicker
;
}
-
(
void
)
setMinLimitDate
:
(
NSDate
*
)
minLimitDate
{
_minLimitDate
=
minLimitDate
;
if
([
_scrollToDate
compare
:
self
.
minLimitDate
]
==
NSOrderedAscending
)
{
_scrollToDate
=
self
.
minLimitDate
;
}
[
self
getNowDate
:
self
.
scrollToDate
animated
:
NO
];
}
@end
DreamSleep/DreamSleep/Vendors/WSDaePickerView/WSDatePickerView.xib
0 → 100755
查看文件 @
fe09f1c
<?xml version="1.0" encoding="UTF-8"?>
<document
type=
"com.apple.InterfaceBuilder3.CocoaTouch.XIB"
version=
"3.0"
toolsVersion=
"20037"
targetRuntime=
"iOS.CocoaTouch"
propertyAccessControl=
"none"
useAutolayout=
"YES"
useTraitCollections=
"YES"
colorMatched=
"YES"
>
<device
id=
"retina4_7"
orientation=
"portrait"
appearance=
"light"
/>
<dependencies>
<deployment
identifier=
"iOS"
/>
<plugIn
identifier=
"com.apple.InterfaceBuilder.IBCocoaTouchPlugin"
version=
"20020"
/>
<capability
name=
"documents saved in the Xcode 8 format"
minToolsVersion=
"8.0"
/>
</dependencies>
<objects>
<placeholder
placeholderIdentifier=
"IBFilesOwner"
id=
"-1"
userLabel=
"File's Owner"
/>
<placeholder
placeholderIdentifier=
"IBFirstResponder"
id=
"-2"
customClass=
"UIResponder"
/>
<view
contentMode=
"scaleToFill"
id=
"iN0-l3-epB"
customClass=
"WSDatePickerView"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"375"
height=
"667"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<subviews>
<view
contentMode=
"scaleToFill"
fixedFrame=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"gvZ-fK-lMh"
>
<rect
key=
"frame"
x=
"0.0"
y=
"221"
width=
"375"
height=
"225"
/>
<autoresizingMask
key=
"autoresizingMask"
flexibleMaxX=
"YES"
flexibleMaxY=
"YES"
/>
<color
key=
"backgroundColor"
red=
"1"
green=
"0.99997437000274658"
blue=
"0.99999129772186279"
alpha=
"0.9847876320422535"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
</view>
</subviews>
<color
key=
"backgroundColor"
red=
"0.0"
green=
"0.0"
blue=
"0.0"
alpha=
"0.40105064655172412"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
<connections>
<outlet
property=
"buttomView"
destination=
"gvZ-fK-lMh"
id=
"1kp-xm-4pD"
/>
</connections>
<point
key=
"canvasLocation"
x=
"-41"
y=
"51"
/>
</view>
</objects>
</document>
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论