Rails 3.1.8 strange timezone behaviour. subtracting dates.to_i gives zero, ruby says dates are different - datetime

I'm upgrading from rails 3 to 3.1.8 (and onwards). A couple of my tests are failing, one of which seemed at first glance to be because of the change from mysql2 gem (0.2.x to 0.3.x). However, it gets a little stranger. Here's what's happening.
In my test I am updating attributes on a model, and checking that they've saved:
...
post :create, :advertisement => #advertisement_attributes
assert_equal assigns(:blah).start_date, #blah_attributes[:start_date]
It is failing saying that they are different times.
If I put a binding.pry and jump in just before the assert_equal this is what I get:
a = assigns(:blah).start_date
b = #blah_attributes[:start_date]
a == b #false
a.to_s #"2012-10-17 20:46:12 UTC"
b.to_s #"2012-10-17 20:46:12 UTC"
a.to_i #1350506772
b.to_i #1350506772
a.to_i - b.to_i #0
So far.. I'm still confused as to why the == is returning false. But what is really odd is if I subtract the dates -
a - b #-0.989403009414673
If anyone can explain what's going on here I'd love to know!
Also, this same test was passing fine in rails 3 (no timezone was set for the application), any pointers to what has changed would also be handy!

Related

DateTimeParseException while trying to perform ZonedDateTime.parse

Using Java 8u222, I've been trying a silly operation and it incurs in an error that I'm not being able to fully understand. The line code:
ZonedDateTime.parse("2011-07-03T02:20:46+06:00[Asia/Qostanay]");
The error:
java.time.format.DateTimeParseException: Text '2011-07-03T02:20:46+06:00[Asia/Qostanay]' could not be parsed, unparsed text found at index 25
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1952)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:597)
at java.time.ZonedDateTime.parse(ZonedDateTime.java:582)
Using the same date (although the timezone could be incorrect, the intention is just testing here), I changed the square bracket's value and it works, I mean:
ZonedDateTime.parse("2011-07-03T02:20:46+06:00[Europe/Busingen]);
It works as expected, as well as other values such:
ZonedDateTime.parse("2011-07-03T02:20:46+06:00[Asia/Ulan_Bator]")
ZonedDateTime.parse("2011-07-03T02:20:46+06:00[SystemV/CST6CDT]")
I found some similar questions such as the one below, but not precisely the same usage that I'm trying / facing.
Error java.time.format.DateTimeParseException: could not be parsed, unparsed text found at index 10
Does someone have an understanding of Java Date API to help me out to grasp what I'm doing wrong here?
Thanks.
Asia/Qostanay is a zone which doesn't exist in the JDK8's list of timezones. It was added later.
If you don't care about the location of the timezone then just splice the [...] part of the string off the end before parsing. Knowing that the time is +06:00 is going to sufficient for almost all purposes.
Alternatively, upgrade to a more recent version of Java.

Why does Julia> (1,2,3) return (1,2,0)

I've been working through the Julia Tutorial, and strangely (1,2,3) returns (1,2,0).
(1,2,3,4) returns (1,2,0,0)
(1,2,3,4,5) returns (1,2,3,4,5) as expected.
It seems that sets of size 3 or 4 replace the 3rd and fourth elements with 0. I don't expect that this is normal behavior but I'm not familiar with the environment so I'm not sure with what I might have done to cause this.
I deleted all julia files from my profile and restarted the interpreter, and the behavior persists.
Version 0.3.5 (2015-01-08 22:33 UTC) under windows executed in cygwin.
Same problem when executed from command.
This is a (very strange!) long standing display bug on Windows. You can read about it at the link - in short, the value is correct but it doesn't display right. It should also be fixed in final release of Julia 0.4, which will use LLVM 3.5 (at least, thats what the thread says).

Upgraded quantstrat 0.7.8 from 0.7.7 then old code does not work

I have upgraded quantstrat package from 0.7.7(installed on Jan 7th 2013) to 0.7.8, however old code does not work properly. looks like we can not put any entry orders niether buy or sell, and only exit orders are executed. Here is the detail. Someone knows major changes in add.rule or applyStrategy function or same issue has been reported?
We set up trading rule by add.rule()
add.rule(f,'ruleSignal',arguments=list(sigcol="DoSell",sigval=TRUE,orderqty=(-1*tradeSize),osFUN='osSUS',ordertype='market',TxnFees="calcTxnFee",prefer='Open'),type='enter',label=gExitLabel)
add.rule(f,'ruleSignal',arguments=list(sigcol="DoBuy", sigval=TRUE,orderqty=tradeSize,osFUN='osBuy',ordertype='market',TxnFees="calcTxnFee",prefer='Price'),type='enter',label=gEnterLabel)
add.rule(f,'ruleSignal',arguments=list(sigcol="DoStop", sigval=TRUE,orderqty=-1*tradeSize,osFUN='osStop',ordertype='stoplimit',threshold='StopLevel',TxnFees="calcTxnFee"),type='risk',label='Stop')
The problem we had is we don't get entry signal when we run applyStrategy ...... It seems that getOrderbook has "Buy" and "Sell" .....
applyStrategy(rs, rs) only applied sell signal ........(not buy)
[1] "2010-11-18 09:00:00 ABC -65660 # 4.6"
[1] "2010-12-07 09:00:00 ABC -37509 # 5.17"
However getOrderBook() recorded "Buy", and "Sell" in order .....
at the same time order.prices were set "0", order.status "replaced" and Prefer "Price" by the system
It is hard to understand what is your problem exactly: "no entry signal", "orderbook has Buy and Sell" (whatever that means), "order.prices were set to 0" ...
I see that you are using your own order sizing functions, could it have something to do with that? You may try dropping your order sizing functions for a test, just to check if your entry orders are being executed.
Otherwise I suggest that you provide a complete example so I can run it and check.
Please be aware that quantstrat is under heavy development and that the code is patched almost on a daily basis, although the version number may not always be bumped up. So make sure that you always download the latest code.
HTH,
Jan Humme.

Clear console for each run of Testacular/Karma + Jasmine

It is difficult for me to catch with the eye a boundary between test runs.
Is it possible to clear console for each run of Testacular/Karma + Jasmine or at least put there something easily catched by the eye, for example a series of newlines?
Note
Currently it is an abandoned question because I am no longer trying to perform tasks described in it. Please do not ask for additional info. Write only if you know for sure what to do. It will help other people.
Write your own reporter, and do whatever you want with it.
Also, if you're on a Mac and use Growl, take a look at karma-growl-reporter
I am not sure to fully understand your need but karma-spec-reporter can give you a detailed review of your test execution. Output example from karma-spec-reporter-example:
array:
push:
PASSED - should add an element
PASSED - should remove an element
FAILED - should do magic (this test will fail) expected [] to include 'magic'
at /home/michael/development/codecentric/karma-spec-reporter-example/node_modules/chai/chai.js:401
...
PhantomJS 1.8.1 (Linux): Executed 3 of 3 (1 FAILED) (0.086 secs / NaN secs)
There's now a reporter available for this: https://github.com/arthurc/karma-clear-screen-reporter
It's working for me on OSX.

How to substract a day/hour/minute from joda-time DateTime in Scala?

I am trying to use joda-time with its Scala wrapper.
Saying val dt is a DateTime and contains a date (zero time), how do I get the date of the day befor it? dt - 1.days doesn't work and gives
"type mismatch" ("found: org.scala_tools.time.Imports.DateTime, required: ?{val -:?}").
Scala-time examples like 2.hours + 45.minutes + 10.seconds don't work either saying that hours is not a member of an Int.
Joda-time examples like DateTime.dayOfWeek().addToCopy(3) don't work either as dayOfWeek, for example, is not a member of org.scala_tools.time.Imports.DateTime.
Formatted DateTimeinput and output seem to work as meant.
UPDATE: Seems to be a bug of NetBeans IDE.It shows the error, while compiler compiles ok and the program works as expected with dt - 1.days syntax.
Seems to be a bug of NetBeans IDE. It shows the error, while compiler compiles ok and the program works as expected with "dt - 1.days" syntax.
It seems that the code cannot find the implicit conversions. Are you sure you import org.scala_tools.time.Imports._ in the scope that you are using it?

Resources