Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.