Skip to content

Commit b131dc9

Browse files
jbranchaudtpope
authored andcommitted
Adjust the timezone offset on the other bound
At certain times of day (based on a person's UTC offset) the migration timestamp generated by `:Emigration CreateATable!` can end up being 24 hours earlier than what it is supposed to be. For instance, when I created a migration on March 31st at 2pm, the following timestamp is created: 20160331190000 (2016-03-31 19:00:00) Later that day at 8:30pm, I created another migration and the following timestamp was created: 20160331013000 (2016-03-31 01:30:00) The timestamp I was expecting is: 20160401013000 (2016-04-01 01:30:00) Obviously this is problematic because it means that at certain times of the day migrations are being created with timestamps that place them out of order. I am in central timezone, so my UTC offset is -5. I noticed that after 7pm (which in UTC is after midnight, so the next day), the timestamps generated by the current implementation of migrationEdit are 24 hours off from what they should be. Part of the timestamp calculation adds 24 hours worth of seconds to the offset when it is less then (-12 * 60 * 60). Similarly, the offset needs to be adjusted by subtracting 24 hours worth of seconds when the offset is greater than (12 * 60 * 60).
1 parent eb388f0 commit b131dc9

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

autoload/rails.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,6 +2789,8 @@ function! s:migrationEdit(cmd,...)
27892789
let offset = local - ts % 86400
27902790
if offset <= -12 * 60 * 60
27912791
let offset += 86400
2792+
elseif offset >= 12 * 60 * 60
2793+
let offset -= 86400
27922794
endif
27932795
let template = 'class ' . rails#camelize(matchstr(arg, '[^!]*')) . " < ActiveRecord::Migration\nend"
27942796
return rails#buffer().open_command(a:cmd, strftime('%Y%m%d%H%M%S', ts - offset).'_'.arg, 'migration',

0 commit comments

Comments
 (0)