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

cellState.date Timezone issue #578

Closed
HusamAamer opened this issue Oct 3, 2017 · 3 comments
Closed

cellState.date Timezone issue #578

HusamAamer opened this issue Oct 3, 2017 · 3 comments
Labels

Comments

@HusamAamer
Copy link

v7.0.6

I noticed that CellState.date is giving date always in UTC but with timezone shifting, here is an example :

when: Region with timezone: Africa/Bamako @UTC
print(Date()) //2017-10-01 08:00:00 +0000
print(cellState.date) //2017-10-01 00:00:00 +0000

when: Region with timezone: Asia/Baghdad @UTC+3
print(Date()) // 2017-10-01 08:00:00 +0000
print(cellState.date) // 2017-09-30 21:00:00 +0000 <-- Notice the time shifting here
it should give (2017-10-01 00:00:00 +0000) or (2017-09-30 21:00:00 +3)

Thanks for sharing your calendar ❤️

@HusamAamer HusamAamer changed the title Timezone issue cellState.date Timezone issue Oct 3, 2017
@patchthecode
Copy link
Owner

patchthecode commented Oct 3, 2017

OK.
The calendar gives you dates in the format you provided in this function.

func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
   // configure your custom calendar here configured to your time zone and locale
   let myCalendar = Calendar(identifier: .gregorian)
   myCalendar.timeZone = // myTimeZone
   myCalendar.locale = // myLocale

   let parameters = ConfigurationParameters(startDate: 
      startDate,
      endDate: endDate,
      calendar: myCalendar)
   return parameters
}

also, whenever you print dates to the console, never print the raw date. Always use a DateFormatter. The formatter should also be in the same format as the calendar you provided in the function above.

let formatter = DateFormatter()
formatter.dateFormat = "yyyy MM dd"
formatter.timeZone = myCalendar.timeZone
formatter.locale = myCalendar.locale
formatter.calendar = myCalendar

print(formatter.string(from: myDate)

The reason for this is that the print function comes with date formatting of it own. Most of the time, it is not the formatting what you would like (especially in you live in eastern countries).
Explanation given here -> #252

@HusamAamer
Copy link
Author

@patchthecode Thanks for explanation, I've corrected the code yesterday and everything is fine now 👍

@patchthecode
Copy link
Owner

Asweome. Closing this issue.

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

No branches or pull requests

2 participants