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

Non-UTC timezone issue #247

Open
zedtux opened this issue Jan 11, 2018 · 8 comments
Open

Non-UTC timezone issue #247

zedtux opened this issue Jan 11, 2018 · 8 comments
Labels
feature New functionalities

Comments

@zedtux
Copy link
Collaborator

zedtux commented Jan 11, 2018

Time records attributes of my application are saved in UTC in RethinkDB, which is fine by me, but now I'd like to show them in the current timezone.

I have updated my Rails app config/application.rb file in order to set the time_zone:

...

module AppName
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.1

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Don't generate system test files.
    config.generators.system_tests = nil

    config.time_zone = 'Paris'
  end
end

And I have updated the NoBrainer initializer:

  ...

  # user_timezone can be configured with :utc, :local, or :unchanged.
  # When reading a Time attribute from a model, the timezone of that attribute
  # is set according to the following setting.
  config.user_timezone = :local

  ...

Restarted everything but my dates and times are still displayed in UTC:

2018-01-11T10:31:56.733+00:00

(This should be with an hour more 11:31:56)

Can you please tell me what am I doing wrong?

@nviennot
Copy link
Collaborator

What's your model code? How did you declare your attributes?

@zedtux
Copy link
Collaborator Author

zedtux commented Jan 11, 2018

Sorry to not have provided my code 😞. Here it is:

class Request
  include NoBrainer::Document

  before_create :populates_created_at

  field :url, type: String
  field :created_at, type: Time, index: true

  private

  def populates_created_at
    self.created_at = Time.zone.now
  end
end

@nviennot
Copy link
Collaborator

Thank you.
Internally, NoBrainer uses Time#getlocal.

Example:

~/brainy (development) > Time.now.utc
=> 2018-01-11 13:29:35 UTC
~/brainy (development) > Time.now.utc.getlocal
=> 2018-01-11 08:29:37 -0500

What do you get?

The settings of the Rails time_zone is not taken in account. Maybe we can have another setting that uses the Rails configuration instead? The place to add this code is here: https://github.com/nviennot/nobrainer/blob/master/lib/no_brainer/document/types/time.rb#L35 Feel free to make a pull request :) :)

@zedtux
Copy link
Collaborator Author

zedtux commented Jan 11, 2018

Thank you @nviennot for your comment 👍.

Right now, I'm working on having AASM compatible with NoBrainer, but the I can try to implement this too.
Thank you for having pointed me to the right place :)

@zedtux
Copy link
Collaborator Author

zedtux commented Jan 12, 2018

I'm done with AASM, if you want to have a look and give feedbacks: aasm/aasm#522.

I will now check for this timestamp issue.

@nviennot
Copy link
Collaborator

Great work!

I put a few comments in the pull request

@zedtux
Copy link
Collaborator Author

zedtux commented Jan 15, 2018

Thank you @nviennot. Where are your comments? I can't see them.

@nviennot
Copy link
Collaborator

Forgot to press "submit review". Should be in

@zedtux zedtux added the feature New functionalities label Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionalities
Projects
None yet
Development

No branches or pull requests

2 participants