Skip to content

Instantly share code, notes, and snippets.

@gander
Last active January 4, 2024 12:45
Show Gist options
  • Save gander/943e39c606b0e568adf0d1432b497dec to your computer and use it in GitHub Desktop.
Save gander/943e39c606b0e568adf0d1432b497dec to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Redmine: Safe Time Entry
// @include https://*/issues/*
// @include https://*/time_entries/*
// ==/UserScript==
jQuery(document).on(
"input change click focus blur",
"#time_entry_hours",
function () {
const $this = jQuery(this);
const color = (function (match) {
if (match === null) return "";
switch (parseInt(match[1] ?? match[2]) % 3) {
case 0:
return "#1e90ff";
case 1:
return "#008000";
case 2:
return "#ff0000";
}
})(/\d+[:h](\d+)|(\d+)m/.exec($this.val()));
$this.css({ "border-color": color, color });
}
);
setTimeout(() => jQuery("#time_entry_hours").trigger('click'), 100);
@gander
Copy link
Author

gander commented Apr 11, 2023

W Redmine czas na raporcie jest zapisany w postaci ułamkowej, gdzie część całkowita to godziny, a ułamkowe to pozostałe minuty. Problemem jest zaś to, że ułamki te są zaokrąglone do dwóch miejsc po przecinku, co oznacza, że dla pewnych wartości następuje utrata lub dodanie wartości. Dla przykładu, 10 minut zyskuje w ten sposób 20 sekund, natomiast 5 minut traci 20 sekund. Napisałem więc ten skrypt, który koloruje pole dodawania czasu pracy, i oznacza na czerwono stratę, na zielono zysk, a na niebiesko wartość bez zmian. Obsługuje formaty 30m, 30min, 1h30, 1h30m, 1:30.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment