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

Option for Persian/Jalali Calendar? #173

Closed
vahids opened this issue Oct 21, 2016 · 39 comments
Closed

Option for Persian/Jalali Calendar? #173

vahids opened this issue Oct 21, 2016 · 39 comments
Assignees

Comments

@vahids
Copy link

vahids commented Oct 21, 2016

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
Copy link
Owner

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
Copy link
Author

vahids commented Oct 21, 2016

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
Copy link
Owner

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
Copy link
Author

vahids commented Oct 21, 2016

U welcome buddy, Thanks to your nice job. 👍

@vahids vahids closed this as completed Oct 21, 2016
@patchthecode
Copy link
Owner

patchthecode commented Oct 21, 2016

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
Copy link
Author

vahids commented Oct 21, 2016

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
Copy link
Owner

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
Copy link
Author

vahids commented Oct 21, 2016

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

@patchthecode
Copy link
Owner

Awesome.

@vahids
Copy link
Author

vahids commented Oct 21, 2016

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
Copy link
Author

vahids commented Oct 21, 2016

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
Copy link
Owner

patchthecode commented Oct 21, 2016

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'
  1. Then run pod install.

To use is all you have to do is this:

calendarView.changeVisibleDirection(to: .rightToLeft)

@patchthecode
Copy link
Owner

patchthecode commented Oct 21, 2016

@vahids Let me know if it works.

If it works, then you can remove your code.

@vahids
Copy link
Author

vahids commented Oct 22, 2016

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
Copy link
Owner

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
Copy link
Owner

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

@vahids
Copy link
Author

vahids commented Oct 22, 2016

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
Copy link
Owner

patchthecode commented Oct 22, 2016

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
Copy link
Author

vahids commented Oct 22, 2016

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
Copy link
Owner

patchthecode commented Oct 22, 2016

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
Copy link
Author

vahids commented Oct 22, 2016

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
Copy link
Owner

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

@vahids
Copy link
Author

vahids commented Oct 22, 2016

Yes, Thank YOU!

@patchthecode
Copy link
Owner

awesome

@vahids
Copy link
Author

vahids commented Oct 22, 2016

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

@patchthecode
Copy link
Owner

patchthecode commented Oct 22, 2016

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

@patchthecode
Copy link
Owner

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 [email protected] 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
#173, or mute the
thread
https://github.com/notifications/unsubscribe-auth/ACU36goGB1mRGycZXyG1ETtVAtvQPIcsks5q2KzqgaJpZM4KdKqd
.

@patchthecode
Copy link
Owner

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

@vahids
Copy link
Author

vahids commented Nov 7, 2016

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
Copy link
Owner

patchthecode commented Nov 7, 2016

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
Copy link

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

@Kalvin126
Copy link

ah. Nevermind I see public func changeVisibleDirection

@AwesDea
Copy link

AwesDea commented Aug 31, 2017

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

@patchthecode
Copy link
Owner

@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
Copy link

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
Copy link
Owner

@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
Copy link

mohammad19991 commented Jun 26, 2018

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

@patchthecode
Copy link
Owner

@mohammad19991 calendarView.semanticContentAttribute ?

I think that is the name of the variable for UICollectionsViews

@mohammad19991
Copy link

yea I ended up using calendarView.semanticContentAttribute, Thanks.

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

No branches or pull requests

6 participants