Skip to content

Commit

Permalink
chore: CalendarManager 추가 (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhnSangHee committed Jun 12, 2022
1 parent 108da92 commit ff3eb50
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
4 changes: 4 additions & 0 deletions iOS/airbnb.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
D00B748A28550AE300B31424 /* CalendarHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00B748928550AE300B31424 /* CalendarHeaderView.swift */; };
D00B748E285591D100B31424 /* CalendarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00B748D285591D100B31424 /* CalendarItem.swift */; };
D00B74902855924800B31424 /* CalendarDiffableDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00B748F2855924800B31424 /* CalendarDiffableDataSource.swift */; };
D00B749228559DD900B31424 /* CalendarManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00B749128559DD900B31424 /* CalendarManager.swift */; };
D01D65EF283C70710067B5E1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01D65EE283C70710067B5E1 /* AppDelegate.swift */; };
D01D65F1283C70710067B5E1 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01D65F0283C70710067B5E1 /* SceneDelegate.swift */; };
D01D65F3283C70710067B5E1 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01D65F2283C70710067B5E1 /* MainViewController.swift */; };
Expand Down Expand Up @@ -134,6 +135,7 @@
D00B748928550AE300B31424 /* CalendarHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarHeaderView.swift; sourceTree = "<group>"; };
D00B748D285591D100B31424 /* CalendarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarItem.swift; sourceTree = "<group>"; };
D00B748F2855924800B31424 /* CalendarDiffableDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarDiffableDataSource.swift; sourceTree = "<group>"; };
D00B749128559DD900B31424 /* CalendarManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarManager.swift; sourceTree = "<group>"; };
D01D65EB283C70710067B5E1 /* airbnb.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = airbnb.app; sourceTree = BUILT_PRODUCTS_DIR; };
D01D65EE283C70710067B5E1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
D01D65F0283C70710067B5E1 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -252,6 +254,7 @@
D00B744C2851CCA200B31424 /* ViewModel */,
D00B744F2851D1D700B31424 /* WeekdayCollectionViewDataSource.swift */,
D00B748F2855924800B31424 /* CalendarDiffableDataSource.swift */,
D00B749128559DD900B31424 /* CalendarManager.swift */,
);
path = Calendar;
sourceTree = "<group>";
Expand Down Expand Up @@ -877,6 +880,7 @@
D068BD002840700B00EF783E /* TabBarController.swift in Sources */,
D01D662A283CB5DB0067B5E1 /* ReservationViewController.swift in Sources */,
D087289B283E7D26009983A5 /* CustomLabel.swift in Sources */,
D00B749228559DD900B31424 /* CalendarManager.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
66 changes: 66 additions & 0 deletions iOS/airbnb/Present/Main/Calendar/CalendarManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// CalendarManager.swift
// airbnb
//
// Created by 안상희 on 2022/06/12.
//

import Foundation

class CalendarManager {
let calendar = Calendar.current

// 한 달 뒤
func plusMonth(date: Date) -> Date {
return calendar.date(byAdding: .month, value: 1, to: date)!
}

// 한 달 전
func minusMonth(date: Date) -> Date {
return calendar.date(byAdding: .month, value: -1, to: date)!
}

// Month
func monthString(date: Date) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "LLLL"

return dateFormatter.string(from: date)
}

// Year
func yearString(date: Date) -> String {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy"

return dateFormatter.string(from: date)
}

// 한 달에 총 몇 일까지 있는지
func daysInMonth(date: Date) -> Int {
let range = calendar.range(of: .day, in: .month, for: date)!

return range.count
}

// Day
func dayOfMonth(date: Date) -> Int {
let components = calendar.dateComponents([.day], from: date)

return components.day!
}

// 월의 첫번째 날짜 출력
func firstOfMonth(date: Date) -> Date {
let components = calendar.dateComponents([.year, .month], from: date)

return calendar.date(from: components)!
}

// input: 1 Jan 2021, result: 5(Friday (6) - 1)
func weekDay(date: Date) -> Int {
let components = calendar.dateComponents([.weekday], from: date)
print("*** weekday \(components.weekday! - 1)")
return components.weekday! - 1
}
}

0 comments on commit ff3eb50

Please sign in to comment.