patchthecode / JTAppleCalendar

The Unofficial Apple iOS Swift Calendar View. Swift calendar Library. iOS calendar Control. 100% Customizable
https://patchthecode.com
MIT License
7.57k stars 808 forks source link

Option for Persian/Jalali Calendar? #173

Closed vahids closed 8 years ago

vahids commented 8 years ago

I made some change in source code and It's changed to Persian calendar and Right to Left. I just want to know is it OK if I change some code in this framework?

patchthecode commented 8 years ago

It is ok. But I need to know the changes you have made so that it will be in future updates of this library forever.

You can do this in two ways. Pick one.

  1. You can tell me here and I will add it. or
  2. You can create a pull request, and I will merge it
vahids commented 8 years ago

I choose 1, because I made change static

JTAppleCalendarSwift.swift line 177 change from:

    var cal = Calendar(identifier: .gregorian)

to:

    var cal = Calendar(identifier: .persian)

It's Changed calendar to Persian.


To change it from LeftToRight to RightToLeft:

JTAppleCalendarSwift.swift Add in Line 282:

    var scalingTransform : CGAffineTransform!
    scalingTransform = CGAffineTransform(scaleX: -1, y: 1);
    cv.transform = scalingTransform

and in ViewController in calendar func add this lines end of function:

    var scalingTransform : CGAffineTransform!
    scalingTransform = CGAffineTransform(scaleX: -1, y: 1);
    myCustomCell.transform = scalingTransform

I don't have any idea how you want make it dynamic and switchable. easy way is add this post in tutorial. Thanks :-)

patchthecode commented 8 years ago

Thanks for the code help. Let me think on this. If I cant do it in code, I will add your post as a tutorial. Thanks!

vahids commented 8 years ago

U welcome buddy, Thanks to your nice job. 👍

patchthecode commented 8 years ago

There is one thing I need to know so that you do not have errors. Does the Persian/jalali calendar have the same in-dates/out-dates like the gregorian calendar?

If yes, then you should have no problems If no, then I will need to do just a very small update.

vahids commented 8 years ago

I don't understand your question, It's a screenshot of current month in Persian/Jalali calendar. and today is 30.

screenshot of simulator 10 21 16 3 14 pm

30 = ۳۰

patchthecode commented 8 years ago

Ok, i cant read your calendar. But is every thing ok with it? If all is well, then great!

Also, I have found a way to add it to the code. I will let you know shortly

vahids commented 8 years ago

Yes, I checked a year with time.ir (Persian data/time reference) calendar and It's correct.

patchthecode commented 8 years ago

Awesome.

vahids commented 8 years ago

owww, new issue :-/

I make an inside header but It's mirrored :D Because of this lines:

var scalingTransform : CGAffineTransform!
scalingTransform = CGAffineTransform(scaleX: -1, y: 1);
myCustomCell.transform = scalingTransform

screen shot 2016-10-21 at 6 14 13 pm

I think I have to find another way for Right to Left

vahids commented 8 years ago

HoHaa 🗡 I found solution. I have to add

var scalingTransform : CGAffineTransform!
scalingTransform = CGAffineTransform(scaleX: -1, y: 1);
headerCell?.transform = scalingTransform

in end of func calendar(_ calendar: JTAppleCalendarView, willDisplaySectionHeader header: JTAppleHeaderView, range: (start: Date, end: Date), identifier: String) delegate

too. So this cell will be mirrored and will be done :D

patchthecode commented 8 years ago

Hey, so I made an update specially for you. 😎 I want you to test it to see if it works when you have the time.

Ensure you save your changes first because doing a pod install will get rid of your changes to the library.

To test the new feature, do the following:

1) Put this in your Podfile

pod 'JTAppleCalendar', :git => 'https://github.com/patchthecode/JTAppleCalendar.git'

2) Then run pod install.

To use is all you have to do is this:

calendarView.changeVisibleDirection(to: .rightToLeft)
patchthecode commented 8 years ago

@vahids Let me know if it works.

If it works, then you can remove your code.

vahids commented 8 years ago

Yes working like charm, Great Work! Just a question I want to put month name in header But I didn't find any method to return month or date for current month.

Thanks again. 👍

patchthecode commented 8 years ago

You have dates. You are the one to come up with the names of the month.

When ever you scroll the calendar, this delegate function is called

func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo)

With this function you have a variable called visibleDates This tells you the visible dates that are on the screen. From these dates, you can know the month. Take a look at the sample project attached to this project. I have code in there that shows you an example of how to get the names of the month.

If you need help, then let me know.

patchthecode commented 8 years ago

let visibleInDates = visibleDates.inDates let visibleOutDates = visibleDates.outDates let visibleMonthDates = visibleDates.monthDates

vahids commented 8 years ago

I found it, but it return Gregorian dates. I know I can convert it to Persian and find the month name. Is it right solution ?

patchthecode commented 8 years ago

is it returning gregorian dates even though you used .persian ?

Are you talking about the sample application?

OR

Are you talking about your app?

The thing is, I do not know any thing about Persian dates. So you will have to help me to understand how to show a Persian date :/

vahids commented 8 years ago

I use .persian in configureCalendar > parameters > calendar

but It print gregorian date

   func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo){
        print(visibleDates.monthDates)
    }

BTW, It's easy to convert with DateFormatter

patchthecode commented 8 years ago

ok do you know how to print a persian date?

I thought that when ever you do this -->

let aDate = Date()

I thought you only got one type of dates. I did not know there is a way to return Persian dates. If you know of a way to return Persian dates, then let me know. Or I can try researching it because I do not know how.

vahids commented 8 years ago

You right there is not any type or return Persian Date. It should be converted to local foramt

let today = visibleDates.monthDates[1]
let persian = Calendar(identifier: .persian)
let formatter = DateFormatter()
formatter.dateStyle = DateFormatter.Style.long
formatter.calendar = persian as Calendar!
formatter.locale = NSLocale(localeIdentifier: "fa_IR") as Locale! // "fa_IR" stands for Persian "ar_??" stands for Islamic ...
formatter.dateFormat = "MMMM"
let date = formatter.string(from: today as Date)

print(date)
patchthecode commented 8 years ago

Cool cool. So all is well now? :D ?

vahids commented 8 years ago

Yes, Thank YOU!

patchthecode commented 8 years ago

awesome

vahids commented 8 years ago

hmm.. new issue 😄 when I use .rightoleft calendar will be mirrored if rotate screen.

patchthecode commented 8 years ago

xD ... i didnt think about that i will look into it

patchthecode commented 7 years ago

Yes it is ok to change to code in the framework. But I need to know what change you made In order to include your changes in version 6.0.1

If I do not know your code change, then future versions will not have your code change. That I why I wanted you to open a request on that link. Are you able to open a new request?

On Fri, Oct 21, 2016 at 5:15 AM, Vahid notifications@github.com wrote:

I made some change in source code and It's changed to Persian calendar and Right to Left. I just want to know is it OK if I change some code in this framework?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/patchthecode/JTAppleCalendar/issues/173, or mute the thread https://github.com/notifications/unsubscribe-auth/ACU36goGB1mRGycZXyG1ETtVAtvQPIcsks5q2KzqgaJpZM4KdKqd .

patchthecode commented 7 years ago

@vahids I just made a change. Let me know if orientation bug is now resolved. I have put the changes on master branch.

vahids commented 7 years ago

I don't know what's going on after updating to xcode 8.1 I have this error:

/Users/vahid/Desktop/PersianCal/Pods/JTAppleCalendar/Sources/JTAppleCalendarView.swift:848:48: Binary operator '>=' cannot be applied to operands of type 'Date' and 'Date!'

this line of code: if !(firstDayOfDate >= self.startOfMonthCache &&

So, I could not test direction.

patchthecode commented 7 years ago

Oh. Yea. that is an XCode 8 bug. They mentioned this in their release notes. You need to update to JTAppleCalendar version 6.0.1 to fix this. Once fixed, you can close this issue :]

Kalvin126 commented 7 years ago

Did not want to make a new issue but it seems var orientation is internal protected. Shouldn't it be public/open?

Kalvin126 commented 7 years ago

ah. Nevermind I see public func changeVisibleDirection

AwesDea commented 7 years ago

Did u changed something again? I can't use changeVisibleDirection function.

patchthecode commented 7 years ago

@AwesDea it is been changed to a final name that i will not change again.

I have changed it to the same name as the one inside a UICOollectionView. This helps everyone in that they would not have to remember any custom names that i makeup anymore.

The name of the variable under the UICOllectionView is this ->

calendarView.semanticContentAttribute = ....

This is now the same name provided by Apple

AtrinNoori commented 7 years ago

hey thanks for the amazing library it helps a lot although I have an issue with it and it is that the first six month of the Persian calendar has 31 days and the second 5 months has 30 days and for the last month it is 29 days but every 4 years in has 30 days and I don't know how to implement it I used Date formatter for The Persian Calendar but it was no good (first screenshot) and I don't know why but when I use current date or "Date()" it is not exact (2nd Screenshot) as u can see it says that today is the 22nd of the month but actually It is the 31 first of the month

screen shot 1396-06-31 at 07 09 26 screen shot 1396-06-31 at 07 11 15
patchthecode commented 7 years ago

@AtrinNoori you also have to give the library a calendar instance setup for persian.

let myCalendar = Calendar(identifier: .persian)
myCalendar.timeZone = ....
myCalendar.locale = ....

let params = ConfigurationParameters(startDate: startDate, endDate: endDate, calendar: myCalendar)
mohammad19991 commented 6 years ago

How can I use the ReadingOrientation it's not in JTAppleCalendarView. I installed 'JTAppleCalendar', '~> 7.1' via Cocoapods.

patchthecode commented 6 years ago

@mohammad19991 calendarView.semanticContentAttribute ?

I think that is the name of the variable for UICollectionsViews

mohammad19991 commented 6 years ago

yea I ended up using calendarView.semanticContentAttribute, Thanks.