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

Time shown on browser is not reflecting local timezone #9

Open
ryokamiya opened this issue Mar 13, 2013 · 2 comments
Open

Time shown on browser is not reflecting local timezone #9

ryokamiya opened this issue Mar 13, 2013 · 2 comments

Comments

@ryokamiya
Copy link
Contributor

Hi,

I would like to know if anyone else also experience the same.
I'm setting the timezon in Django:
settings.py
TIME_ZONE = 'Asia/Tokyo'

... that helps save my Tokyo timezone inputs into SQLite DB in UTC.

However, browser renders the UTC times as it is, and it's not reflecting the browser/client time locale.

I found that the codes in the timeline.js by Verite that offset OTC time to the local, but not sure why it's not working in Django's model.

@abdallah
Copy link
Owner

Can you point me to the fix or related code in timeline.js ?
Please see the available options per https://github.com/VeriteCo/TimelineJS#config-options

@ryokamiya
Copy link
Contributor Author

I figured it out that Verite's TimelineJS doesn't support timezone on its rendering. That will show whatever passed over in JSON input. It uses another third party module DateTimeFormat that can offset timezone from UTC, but the option is turned off - the third argument in the line below.

timeline.js

            _date = dateFormat(d, format, false);

The solution we have to reflect timezone are either we change Verite's TimelineJS or supports it from Django-TimelineJS. The first option will take the user setting from browser, and the latter case will take from Django's settings.py.

models.py

    from pytz import timezone
    import pytz
    from django.utils import timezone

    class TimelineEvent(models.Model):

          def to_dict(self):
              d = {}
              user_timezone = timezone.get_current_timezone()
              start_date_local = self.start_date.astimezone(user_timezone)
              d['startDate'] = start_date_local.strftime('%Y,%m,%d,%H,%M')
              end_date_local = self.end_date.astimezone(user_timezone)
              d['endDate'] = end_date_local.strftime('%Y,%m,%d,%H,%M') if self.end_date else d['startDate']
              d['headline'] = self.headline
              d['text'] = self.text
              d['asset'] = {'media': self.asset_media, 'credit': self.asset_credit, 'caption': self.asset_caption }
              return d

Since I need additional information of hour & minute besides date, I have changed a model from DateField to DateTimeField for my own use. If this also helps others, I can send this via Pull Request.

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

No branches or pull requests

2 participants