FSCalendar icon indicating copy to clipboard operation
FSCalendar copied to clipboard

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

Open hamzakhanfcb10 opened this issue 7 years ago • 41 comments

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

hamzakhanfcb10 avatar Dec 10 '17 10:12 hamzakhanfcb10

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.

oenama avatar Dec 20 '17 13:12 oenama

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

MehulSojitra16 avatar Dec 27 '17 10:12 MehulSojitra16

any one got a solution?

tarikhs avatar Apr 10 '18 21:04 tarikhs

@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

Husseinhj avatar Apr 11 '18 04:04 Husseinhj

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

rehannali avatar Apr 12 '18 07:04 rehannali

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

Husseinhj avatar Apr 12 '18 09:04 Husseinhj

@rehannali @tarikhs

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


Date picker


Date picker

Husseinhj avatar Apr 12 '18 12:04 Husseinhj

@Husseinhj Shukran Brother!

tarikhs avatar Apr 22 '18 07:04 tarikhs

@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

VidyaRajan7 avatar Jul 25 '18 06:07 VidyaRajan7

I did fix this at commit

@VidyaRajan7 Use the last version of FSCalendar+Persian v2.8.1

Husseinhj avatar Jul 25 '18 06:07 Husseinhj

Ok Thank You @Husseinhj

VidyaRajan7 avatar Jul 25 '18 06:07 VidyaRajan7

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

VidyaRajan7 avatar Jul 25 '18 07:07 VidyaRajan7

@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";
}

Husseinhj avatar Jul 25 '18 07:07 Husseinhj

@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")
    }

omarhassansadek avatar Sep 30 '18 09:09 omarhassansadek

@omarhassansadek Did you use implement FSCalendar delegate method?

#pragma mark - FSCalendarDataSource

- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar
{
    return [self.dateFormatter dateFromString:@"2016-07-08"];
}

Husseinhj avatar Sep 30 '18 10:09 Husseinhj

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.

anjusr avatar May 13 '19 07:05 anjusr

@anjusr Fixed in v2.9.3

Husseinhj avatar May 23 '19 09:05 Husseinhj

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

mostafawanni94 avatar Jun 14 '20 08:06 mostafawanni94

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.

OmarHassan25 avatar Jan 24 '22 08:01 OmarHassan25

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

Husseinhj avatar Jan 24 '22 08:01 Husseinhj

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.

mostafawanni94 avatar Jan 24 '22 09:01 mostafawanni94

@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

OmarHassan25 avatar Jan 24 '22 09:01 OmarHassan25

I'll fix this during this week. @OmarHassan25

Husseinhj avatar Jan 24 '22 09:01 Husseinhj

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.

mostafawanni94 avatar Jan 24 '22 09:01 mostafawanni94

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

Thanks in advance

OmarHassan25 avatar Jan 24 '22 09:01 OmarHassan25

@Husseinhj any updates please?

OmarHassan25 avatar Jan 27 '22 09:01 OmarHassan25

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

Husseinhj avatar Jan 27 '22 09:01 Husseinhj

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

OmarHassan25 avatar Feb 02 '22 06:02 OmarHassan25

@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 avatar Feb 06 '22 12:02 Husseinhj

@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 avatar Feb 06 '22 12:02 Husseinhj

@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,

OmarHassan25 avatar Feb 06 '22 14:02 OmarHassan25

@OmarHassan25 Like this? image

Husseinhj avatar Feb 06 '22 16:02 Husseinhj

@OmarHassan25 Like this? image

@Husseinhj Yes, This is my target,

OmarHassan25 avatar Feb 06 '22 16:02 OmarHassan25

@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")
    }

Husseinhj avatar Feb 06 '22 16:02 Husseinhj

@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,

OmarHassan25 avatar Feb 06 '22 16:02 OmarHassan25

@OmarHassan25

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

Husseinhj avatar Feb 06 '22 16:02 Husseinhj

@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.

OmarHassan25 avatar Feb 06 '22 16:02 OmarHassan25

@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?

Husseinhj avatar Feb 06 '22 16:02 Husseinhj

@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

OmarHassan25 avatar Feb 07 '22 10:02 OmarHassan25

@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 avatar Feb 09 '22 11:02 Husseinhj

@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.

OmarHassan25 avatar Feb 13 '22 07:02 OmarHassan25