Created
November 26, 2017 22:16
-
-
Save nicola/25774d490a1e2b07e38061cdd6d09042 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This script counts how many days you have been in the USA | |
// This is a personal script, use it at your own risk | |
// This is not an official tool and it can do wrong calculations | |
// which might result in loss in visa status, green card, citizenship | |
// and whatever you can think of | |
// This extracts data from the i94 website from the history result view | |
function daysInYear(year) { | |
var recs = angular.element(".history-results").scope().vm.recs | |
var count = 0 | |
var prev = null | |
recs.forEach(function (rec) { | |
if (rec.eventType === "Arrival") { | |
if (prev) { | |
var departure = new Date(rec.eventDate); | |
var arrival = new Date(prev); | |
if (arrival.getUTCFullYear() != year) { return } | |
var timeDiff = Math.abs(departure.getTime() - arrival.getTime()); | |
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); | |
count += diffDays | |
console.log(count, "from", rec.eventDate, "to", prev) | |
} | |
} else { // Departure | |
prev = rec.eventDate | |
} | |
}) | |
console.log("You have been:", count, "in", year) | |
} | |
daysInYear(2016) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment