}
};
+ openils.Util.getNodeByName = function(name, contextNode) {
+ return dojo.query('[name=' + name + ']', contextNode)[0];
+ };
+
+ // Returns the provided date as YYYY-MM-DD for the local time zone.
+ // If no date is provided, the current date is used.
+ openils.Util.getYMD= function(d) {
+ if (!d) d = new Date();
+
+ // toISOString returns a UTC date. Mangle our 'now' date to
+ // force its UTC verion to match that of the local version
+ // once the timezone is stripped away.
+ // E.g. if the local time zone is -0500, subract 5 hours
+ // from the date before translating to an ISO string.
+ // Note: tz offset is positive for locales behind UTC.
+ d.setTime(d.getTime() - (d.getTimezoneOffset() * 60 * 1000));
+
+ return d.toISOString().replace(/T.*/, '');
+ }
+
+ // Creates a date in the local time zone from the provided YYYY-MM-DD.
+ // Parsing a bare YYYY-MM-DD value creates a UTC date, causing the
+ // resulting date to be off by a day in the local time zone.
+ openils.Util.fromYMD = function(ymd) {
+ if (!ymd) return null;
+ var parts = ymd.split('-');
+ return new Date(parts[0], Number(parts[1]) - 1, Number(parts[2]));
+ }
+
}