Skip to content
This repository has been archived by the owner. It is now read-only.

Support forcing a certain timezone/locale #10379

Closed
matsbryntse opened this issue Feb 13, 2012 · 11 comments

Comments

Projects
None yet
6 participants
@matsbryntse
Copy link

commented Feb 13, 2012

m...@mankz.com commented:

Not sure if this is doable, but it would be fantastic if Phantom could 'fake' its timezone. This would be nice when adding tests for rare DST bugs, in Brazil for example.

Disclaimer:
This issue was migrated on 2013-03-15 from the project's former issue tracker on Google Code, Issue #379.
🌟   3 people had starred this issue at the time of migration.

@ariya

This comment has been minimized.

Copy link
Owner

commented Mar 5, 2012

ariya.hi...@gmail.com commented:

Is it possible just to mock it via the Date object?

See also examples/unrandomize.js.

Some related info:
http://ariya.ofilabs.com/2011/10/detecting-browser-sniffing-2.html
http://ariya.ofilabs.com/2011/09/water-lily.html

@matsbryntse

This comment has been minimized.

Copy link
Author

commented Mar 5, 2012

m...@mankz.com commented:

Doubt it, since you'll want the local dst transitions for every locale etc... Maybe this is just impossible to do easily...

@ariya

This comment has been minimized.

Copy link
Owner

commented Mar 15, 2012

ariya.hi...@gmail.com commented:

Can you elaborate? Perhaps giving a more detailed step-by-step scenario of what you want to achieve.

@matsbryntse

This comment has been minimized.

Copy link
Author

commented Mar 15, 2012

m...@mankz.com commented:

I want to be able to test the Brazil daylight savings, which is quite crazy. I currently test this manually by setting the OS timezone to Brazil. Would be neat if Phantom could be configured with the TZ to use.

@ariya

This comment has been minimized.

Copy link
Owner

commented Mar 16, 2012

ariya.hi...@gmail.com commented:

I believe this is remote doable, but it's definitely outside the scope of current PhantomJS direction.

 
Metadata Updates

  • Status updated: WontFix

@ariya ariya closed this Mar 16, 2012

@richardthombs

This comment has been minimized.

Copy link

commented Apr 7, 2013

I would really like to see support for forcing the timezone too. The bootstrap-datepicker project needs tests for different timezones and in/out of DST.

@davidcornu

This comment has been minimized.

Copy link

commented Feb 25, 2014

Found a solution for this. Turns out PhantomJS, like Node, supports setting the local timezone via the TZ environment variable.

$ echo "console.log(new Date)" | TZ="America/Montreal" phantomjs
phantomjs> Tue Feb 25 2014 16:08:21 GMT-0500 (EST)
$ echo "console.log(new Date)" | TZ="UTC" phantomjs
phantomjs> Tue Feb 25 2014 21:08:39 GMT+0000 (UTC)
@richardthombs

This comment has been minimized.

Copy link

commented Feb 26, 2014

Thanks @davidcornu !

@vyscond

This comment has been minimized.

Copy link

commented Nov 17, 2016

@davidcornu Do you know how could i pass the TZ through selenium? Or should i have to kind of create small shell scripts to wrap my phantom call?

@davidcornu

This comment has been minimized.

Copy link

commented Nov 17, 2016

@vyscond I don't know much about Selenium unfortunately. My guess is that you'd have to make sure the TZ environment variable is set wherever you're spawning the phantomjs process.

@chengyiuchun

This comment has been minimized.

Copy link

commented Feb 5, 2017

@vyscond If you are using detro's phantomjs driver, there is actually a method to set the environment when it starts the phantomjs executable. https://github.com/detro/ghostdriver/blob/master/binding/java/src/main/java/org/openqa/selenium/phantomjs/PhantomJSDriverService.java#L401

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.