WenchaoD / FSCalendar

A fully customizable iOS calendar library, compatible with Objective-C and Swift
MIT License
10.61k stars 1.94k forks source link

Date selection and Header title displaying wrong dates, months and year in arabic #843

Open hamzakhanfcb10 opened 6 years ago

hamzakhanfcb10 commented 6 years ago

Hi @WenchaoD ,

I am using your awesome library again but this time in Arabic in xcode 9 ios 11. I am facing this issue in RLT. When i change the system language the header title is displaying irrelevant date.

screen shot 2017-12-10 at 3 15 42 pm

This is the code for initial calendar setup.

 func setupCalendar(calendarView : FSCalendar){
        calendarView.allowsMultipleSelection = false
        calendarView.scrollDirection = .horizontal
        calendarView.scrollEnabled = true
        calendarView.swipeToChooseGesture.isEnabled = true
        calendarView.calendarHeaderView.backgroundColor = UIColor.init(hex: "131114")
        calendarView.bottomBorder.backgroundColor = UIColor.clear
        calendarView.appearance.headerDateFormat = "MMMM - YYYY"
        calendarView.appearance.caseOptions = [.headerUsesUpperCase,.weekdayUsesSingleUpperCase]
        calendarView.appearance.borderRadius = 0.2
        calendarView.appearance.todayColor = currenDateColor
        calendarView.appearance.todaySelectionColor = currenDateColor
         calendarView.today = nil
}

  func minimumDate(for calendar: FSCalendar) -> Date {
        return Date()
    }

 func moveBack(calendarView : FSCalendar){

          var val = -1
        if language.currentAppleLanguage() == "ar"{
            val = 1
        }

        let gregorian = NSCalendar.init(calendarIdentifier: .gregorian)

        let mmdate = gregorian?.date(byAdding: .month, value: val, to: calendarView.currentPage, options: [])
        calendarView.setCurrentPage(mmdate!, animated: true)

     //   let previousMonth = self.gre

//        let previousMonth = calendarView.date(bySubstractingMonths: val, from: calendarView.currentPage)
//        calendarView.setCurrentPage(previousMonth, animated: true)
//
    }

    func moveForward(calendarView : FSCalendar){

        var val = 1
        if language.currentAppleLanguage() == "ar"{
            val = -1
        }
        let gregorian = NSCalendar.init(calendarIdentifier: .gregorian)
        let mmdate = gregorian?.date(byAdding: .month, value: val, to: calendarView.currentPage, options: .matchLast)
        calendarView.setCurrentPage(mmdate!, animated: true)

    }

As you can see the date in header is not correct. When i select a date from the calendar it is displaying wrong date value.

Need help urgently please. Thanks

oenama commented 6 years ago

had the same issue. that's how I ended up fixing it :

    if  isCurrentLanguageRTL() {
        calendar.locale = Locale(identifier: "ar")
        calendar.calendarHeaderView.calendar.locale = Locale(identifier: "ar")

    }else {
        calendar.locale = Locale(identifier: "en_EN")
        calendar.calendarHeaderView.calendar.locale =  Locale(identifier: "en_EN")

     }

you need to change headerView locale too.

MehulSojitra16 commented 6 years ago

Same issue here. I have tried above solution but still facing same issue in year. Header year display wrong.

The main calendar display correct date while select the date but problem with only above header date(Horizontal scroll view).

simulator screen shot - iphone 5s - 2017-12-27 at 16 46 32

tarikhs commented 6 years ago

any one got a solution?

Husseinhj commented 6 years ago

@tarikhs You can use my forked version full support RTL languages https://github.com/Husseinhj/FSCalendar It’s all really support persian, if you want to support arabic i will give you 1 hour

rehannali commented 6 years ago

@Husseinhj Hi, Is your calendar support both English and arabic languages? I'm working on multilingual app and need both languages.

Husseinhj commented 6 years ago

@rehannali yeah dude, it’s support RTL (Persian, Arabic ,...) and LTR (English ,...)

Husseinhj commented 6 years ago

@rehannali @tarikhs

I've updated my repo to support Arabic v2.8.0


Date picker


Date picker

tarikhs commented 6 years ago

@Husseinhj Shukran Brother!

VidyaRajan7 commented 6 years ago

@Husseinhj , The app is crashed when i select any calendar from your app. The reason is : -[__NSCFConstantString isRTLCalendar]: unrecognized selector sent to instance. I have downloaded it from your v2.8.0

Husseinhj commented 6 years ago

I did fix this at commit

@VidyaRajan7 Use the last version of FSCalendar+Persianv2.8.1

VidyaRajan7 commented 6 years ago

Ok Thank You @Husseinhj

VidyaRajan7 commented 6 years ago

@Husseinhj
If i want to display calendar in Arabic, how can i do it?

Husseinhj commented 6 years ago

@VidyaRajan7 It's really simple, Look at the example and use your locale and calendar except for Persian. Like this :


- (void)loadView
{
    UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    view.backgroundColor = [UIColor whiteColor];
    self.view = view;

    FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navigationController.navigationBar.frame), view.frame.size.width, view.frame.size.height - CGRectGetMaxY(self.navigationController.navigationBar.frame))];

    calendar.locale = [NSLocale localeWithLocaleIdentifier:@"ar_SA"];
    calendar.identifier = NSCalendarIdentifierIslamic; //or NSCalendarIdentifierIslamicCivil 
    calendar.firstWeekday = 7;

. . . . . .  . .

}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierIslamic];
    self.dateFormatter = [[NSDateFormatter alloc] init];
    self.dateFormatter.dateFormat = @"yyyy-MM-dd";

    // Uncomment this to perform an 'initial-week-scope'
    // self.calendar.scope = FSCalendarScopeWeek;

    // For UITest
    self.calendar.accessibilityIdentifier = @"calendar";
}
omarhassansadek commented 6 years ago

@Husseinhj find error in year when use pod 'FSCalendar+Persian'

screen shot 2018-09-30 at 11 33 18 am

my code if L102Language.currentAppleLanguage()=="ar"{ ClanderDate.locale=Locale(identifier: "ar_DZ") //ClanderDate.calendarHeaderView.calendar.locale = Locale(identifier: "ar_DZ") ClanderDate.identifier = NSCalendar.Identifier.islamic.rawValue

    }
    else{
    ClanderDate.locale=Locale(identifier: "en_US_POSIX")
  //  ClanderDate.calendarHeaderView.calendar.locale = Locale(identifier: "en_US_POSIX")
    }
Husseinhj commented 6 years ago

@omarhassansadek Did you use implement FSCalendar delegate method?

#pragma mark - FSCalendarDataSource

- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar
{
    return [self.dateFormatter dateFromString:@"2016-07-08"];
}
anjusr commented 5 years ago
self.calendar.scope = FSCalendarScopeWeek

@VidyaRajan7 It's really simple, Look at the example and use your locale and calendar except for Persian. Like this :

- (void)loadView
{
    UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    view.backgroundColor = [UIColor whiteColor];
    self.view = view;

    FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.navigationController.navigationBar.frame), view.frame.size.width, view.frame.size.height - CGRectGetMaxY(self.navigationController.navigationBar.frame))];

    calendar.locale = [NSLocale localeWithLocaleIdentifier:@"ar_SA"];
    calendar.identifier = NSCalendarIdentifierIslamic; //or NSCalendarIdentifierIslamicCivil 
    calendar.firstWeekday = 7;

. . . . . .  . .

}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.gregorian = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierIslamic];
    self.dateFormatter = [[NSDateFormatter alloc] init];
    self.dateFormatter.dateFormat = @"yyyy-MM-dd";

    // Uncomment this to perform an 'initial-week-scope'
    // self.calendar.scope = FSCalendarScopeWeek;

    // For UITest
    self.calendar.accessibilityIdentifier = @"calendar";
}

Hi I m using v2.9.2. I want calendar in arabic . When i used this code, I'm not getting current year with current month calender. I checked in your example LoadViewExampleViewController by changing it to this code:

    calendar.locale = Locale(identifier: "ar_SA")
    calendar.calendarIdentifier = NSCalendar.Identifier.islamic.rawValue
    calendar.calendarHeaderView.calendar.calendarIdentifier = NSCalendar.Identifier.islamic.rawValue
    calendar.firstWeekday = 7

It's not showing the current date month. Please help me.

Husseinhj commented 5 years ago

@anjusr Fixed in v2.9.3

mostafawanni94 commented 4 years ago

wrong year in arabic language it is not fixed note : i add FSCalendar in UIView not in code

OmarHassan25 commented 2 years ago

I have the same issue, I am using the FSCalendar+Persian pod, and the date header shows wron g dates after changing the application language.

Husseinhj commented 2 years ago

@OmarHassan25 Could send me a snippet code or screenshot to see the problem?

mostafawanni94 commented 2 years ago

I fixed it and I don’t remember how and I don’t have a code

On Mon, 24 Jan 2022 at 09:49, Hussein Habibi Juybari < @.***> wrote:

@OmarHassan25 https://github.com/OmarHassan25 Could send me a snippet code or screenshot to see the problem?

— Reply to this email directly, view it on GitHub https://github.com/WenchaoD/FSCalendar/issues/843#issuecomment-1019854284, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFRK53I7J3PVTPTMDJLKEKTUXUHBRANCNFSM4EHRYYSQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

--

Mustafa Wanni

Information Engineering in Artificial Intelligence

+963993162549 | Skype :Mustafa.wanni.94

https://www.facebook.com/https://www.facebook.com/mostafa.wane https://in.linkedin.com/in/mustafa-wani-a142ab72 https://api.whatsapp.com/send?phone=+963993162549 https://www.instagram.com/mustafawanni/

Information Engineering is my passion - There is nothing like dynamism and creativity with a large dose of technologies and coding.

OmarHassan25 commented 2 years ago

@OmarHassan25 Could send me a snippet code or screenshot to see the problem?

@Husseinhj check this, please

Screen Shot 2022-01-24 at 12 11 40 PM
 self.localString = MOLHLanguage.currentAppleLanguage()

//        meetingCalendar.collectionView.scroll
        meetingCalendar.delegate = self
        meetingCalendar.dataSource = self
        meetingCalendar.locale = Locale(identifier: localString)
        //meetingCalendar.appearance.headerDateFormat
        meetingCalendar.appearance.titleFont = FontFamily.FSAlbertArabicWeb.regular.font(size: 14)
        meetingCalendar.appearance.weekdayFont = FontFamily.FSAlbertArabicWeb.regular.font(size: 16)
        meetingCalendar.appearance.headerTitleFont = FontFamily.FSAlbertArabicWeb.regular.font(size: 16)
        meetingCalendar.firstWeekday = 7
        meetingCalendar.appearance.weekdayTextColor = ColorName.mtDarkGreen.color
        meetingCalendar.appearance.headerTitleColor = ColorName.mtDarkGreen.color
        meetingCalendar.appearance.titlePlaceholderColor = ColorName.colorD4D8DB.color
        meetingCalendar.appearance.selectionColor = ColorName.mtGreen.color
        meetingCalendar.appearance.borderRadius = 1
        meetingCalendar.appearance.eventOffset = CGPoint(x: 0, y: -7)

        meetingCalendar.bottomBorder.isHidden = true
        meetingCalendar.clipsToBounds = true
        meetingCalendar.appearance.caseOptions = FSCalendarCaseOptions.weekdayUsesSingleUpperCase
Husseinhj commented 2 years ago

I'll fix this during this week. @OmarHassan25

mostafawanni94 commented 2 years ago

Thanks 😊

On Mon, 24 Jan 2022 at 10:18, Hussein Habibi Juybari < @.***> wrote:

I'll fix this during this week. @OmarHassan25 https://github.com/OmarHassan25

— Reply to this email directly, view it on GitHub https://github.com/WenchaoD/FSCalendar/issues/843#issuecomment-1019881062, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFRK53OI34EFVKQBX7CY2ZLUXUKNLANCNFSM4EHRYYSQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

--

Mustafa Wanni

Information Engineering in Artificial Intelligence

+963993162549 | Skype :Mustafa.wanni.94

https://www.facebook.com/https://www.facebook.com/mostafa.wane https://in.linkedin.com/in/mustafa-wani-a142ab72 https://api.whatsapp.com/send?phone=+963993162549 https://www.instagram.com/mustafawanni/

Information Engineering is my passion - There is nothing like dynamism and creativity with a large dose of technologies and coding.

OmarHassan25 commented 2 years ago

@Husseinhj Appreciate your fast response, waiting for the fix as promised,

Thanks in advance

OmarHassan25 commented 2 years ago

@Husseinhj any updates please?

Husseinhj commented 2 years ago

@OmarHassan25 I'll fix it on Saturday when I get back from vacation

OmarHassan25 commented 2 years ago

@Husseinhj I hope that there are good news about the fix,

Husseinhj commented 2 years ago

@OmarHassan25

You should add locale and calendar identifier to fixed that:

meetingCalendar.locale = NSLocale(localeIdentifier: "ar-ae") as Locale
meetingCalendar.calendarIdentifier = NSCalendar.Identifier.islamic.rawValue
Husseinhj commented 2 years ago

@OmarHassan25

You should add locale and calendar identifier to fixed that:

meetingCalendar.locale = NSLocale(localeIdentifier: "ar-ae") as Locale
meetingCalendar.calendarIdentifier = NSCalendar.Identifier.islamic.rawValue
OmarHassan25 commented 2 years ago

@Husseinhj This will not solve the issue, I need to use gregorian calendar with the Arabic language, I don't need to use Islamic calendar,

Husseinhj commented 2 years ago

@OmarHassan25 Like this? image

OmarHassan25 commented 2 years ago

@OmarHassan25 Like this? image

@Husseinhj Yes, This is my target,

Husseinhj commented 2 years ago

@OmarHassan25

You can use this code snippet to achieve your goal:

    override func loadView() {
        let view = UIView(frame: UIScreen.main.bounds)
        view.backgroundColor = UIColor.white
        self.view = view
        let calendar = FSCalendar(frame: CGRect(x: 0, y: (navigationController?.navigationBar.frame.maxY)!, width: view.frame.size.width, height: view.frame.size.height - (navigationController?.navigationBar.frame.maxY)!))

        view.addSubview(calendar)
        self.calendar = calendar

        calendar.delegate = self
        calendar.dataSource = self
        calendar.locale = NSLocale(localeIdentifier: "ar-ae") as Locale
        calendar.calendarIdentifier = NSCalendar.Identifier.gregorian.rawValue

        calendar.firstWeekday = 7
        calendar.appearance.borderRadius = 1
        calendar.appearance.eventOffset = CGPoint(x: 0, y: -7)

        calendar.clipsToBounds = true
        calendar.appearance.caseOptions = FSCalendarCaseOptions.weekdayUsesSingleUpperCase

        calendar.register(RangePickerCell.self, forCellReuseIdentifier: "cell")
    }
OmarHassan25 commented 2 years ago

@Husseinhj The issue comes when I change the application language while the app is running, if I killed the app and opened it again everything works fine,

If I opened the app with EN lang then changed to Arabic then the issue arises, If I removed the app from the recent apps menu and opened it again everything works as expected.

I hope that the issue is now more clear to you,

Husseinhj commented 2 years ago

@OmarHassan25

After changing your application language, did you update or regenerate your calendar view?

OmarHassan25 commented 2 years ago

@Husseinhj I recreate the full app navigation stack after changing the app language, so the calendar view is recreated again, So all my app is regenerated after the app language change, I use MOLHLanguage to manage my application locale.

Husseinhj commented 2 years ago

@OmarHassan25 Is it possible for you to create a sample with the MOLHLanguage library and an exact scenario so we can work together to figure out the issue?

OmarHassan25 commented 2 years ago

@Husseinhj Here is the demo, https://drive.google.com/file/d/1UgEdfVXY_F24fmatL5wyjlGN8Y-c-FzN/view?usp=sharing

Steps to reproduce the issue, 1 - Open the app 2- Click go to calendar 3- Click change language from top right 4- repeat step3 2 and 3 again until the problem appears.

Simulator Screen Shot - iPhone 13 Pro Max - 2022-02-07 at 13 15 05

Husseinhj commented 2 years ago

@OmarHassan25 I ran your sample project and found the issue. The library is unable to update states, so it displays the wrong year. It is better to use the calendar view in run-time rather than design mode.

Like this:

@IBOutlet weak var containerView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        let calender = FSCalendar.init()
        let current  = MOLHLanguage.currentAppleLanguage()
        //        calender.locale = Locale(identifier: current)
        calender.locale = NSLocale(localeIdentifier: "ar-ae") as Locale
        calender.calendarIdentifier = NSCalendar.Identifier.gregorian.rawValue

        containerView.addSubview(calender)

        calender.translatesAutoresizingMaskIntoConstraints = false

        NSLayoutConstraint.activate([
            calender.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
            calender.topAnchor.constraint(equalTo: containerView.safeAreaLayoutGuide.topAnchor),
            calender.bottomAnchor.constraint(equalTo: containerView.bottomAnchor),
            calender.trailingAnchor.constraint(equalTo: containerView.trailingAnchor)
        ])
    }

    @IBAction func gotoChangeBtn(_ sender: Any) {
        MOLH.setLanguageTo(MOLHLanguage.currentAppleLanguage() == "en" ? "ar-ae" : "en")
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.startNavigation()

    }
OmarHassan25 commented 2 years ago

@OmarHassan25 I ran your sample project and found the issue. The library is unable to update states, so it displays the wrong year. It is better to use the calendar view in run-time rather than design mode.

Like this:

@IBOutlet weak var containerView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        let calender = FSCalendar.init()
        let current  = MOLHLanguage.currentAppleLanguage()
        //        calender.locale = Locale(identifier: current)
        calender.locale = NSLocale(localeIdentifier: "ar-ae") as Locale
        calender.calendarIdentifier = NSCalendar.Identifier.gregorian.rawValue

        containerView.addSubview(calender)

        calender.translatesAutoresizingMaskIntoConstraints = false

        NSLayoutConstraint.activate([
            calender.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
            calender.topAnchor.constraint(equalTo: containerView.safeAreaLayoutGuide.topAnchor),
            calender.bottomAnchor.constraint(equalTo: containerView.bottomAnchor),
            calender.trailingAnchor.constraint(equalTo: containerView.trailingAnchor)
        ])
    }

    @IBAction func gotoChangeBtn(_ sender: Any) {
        MOLH.setLanguageTo(MOLHLanguage.currentAppleLanguage() == "en" ? "ar-ae" : "en")
        let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.startNavigation()

    }

@Husseinhj Thanks a lot for this solution, this solves my problem.