Vrijeme

paket "vrijeme";

The vrijeme package provides a way to work with local time. The package includes the following functions and properties:

  1. vrijemeSada
  2. vrijemeIzTeksta
  3. vrijemePoFormatu
  4. Vrijeme

All four functions return a Vrijeme object, which contains the following functions and properties:

  1. sati
  2. minute
  3. sekunde
  4. nanosekunde
  5. plusSati
  6. minusSati
  7. plusMinuta
  8. minusMinuta
  9. plusSekundi
  10. minusSekundi
  11. plusNanosekundi
  12. minusNanosekundi
  13. periodIzmedju
  14. jePoslije
  15. jePrije
  16. naDatum
  17. jednako

Package functions

vrijemeSada

The vrijemeSada function returns a Vrijeme object representing the current time from the system clock in the default time-zone.

var now = vrijemeSada();
ispis(now.sati, ":", now.minute);
14:29

vrijemeIzTeksta

The vrijemeIzTeksta function parses a Vrijeme object out of a provided tekst in the HH:mm:ss format.

var time = vrijemeIzTeksta("14:44:00");
ispis(time.sati, ":", time.minute);
14:44

Invalid tekst example:

var time = vrijemeIzTeksta("25::44::00");
Error: Cannot parse Vrijeme from tekst "25::44::00"

vrijemePoFormatu

The vrijemePoFormatu function parses a Vrijeme object out of a provided tekst according to the provided format.

var time = vrijemePoFormatu("14 44 00", "HH mm ss");
ispis(time.sati, ":", time.minute);
14:44

Invalid date example:

var time = vrijemeIzTeksta("25 44 00", "HH mm ss");
Error: Cannot parse Vrijeme from tekst "25 44 00".

Invalid format example:

var time = vrijemeIzTeksta("14 44 00", "HH hh hh");

<code style=“color: red;”> Error: ‘HH hh hh’ is not a valid time format.

Vrijeme constructor

You can use the Vrijeme constructor to construct a Vrijeme object by providing a value for hours, minutes and seconds.

var v = Vrijeme(15, 22, 0);

ispis(v.sati, ":", v.minute);
15:22

Vrijeme object

sati

The sati property is a broj holding the hours part of the Vrijeme object.

var v = Vrijeme(15, 22, 0);

ispis(v.sati);
15

minute

The minute property is a broj holding the minutes part of the Vrijeme object.

var v = Vrijeme(15, 22, 0);

ispis(v.minute);
22

sekunde

The sekunde property is a broj holding the seconds part of the Vrijeme object.

var v = Vrijeme(15, 22, 33);

ispis(v.sekunde);
33

nanosekunde

The nanosekunde property is a broj holding the nanoseconds part of the Vrijeme object.

var v = Vrijeme(15, 22, 33);

ispis(v.nanosekunde);
0

plusSati

The plusSati function returns a copy of the calling Vrijeme object with the specified number of hours added. The original Vrijeme object remains unchanged.

var v = Vrijeme(15, 22, 33);

var nv = v.plusSati(2);
ispis(nv.sati, ":", nv.minute);
17:22

minusSati

The minusSati function returns a copy of the calling Vrijeme object with the specified number of hours subtracted. The original Vrijeme object remains unchanged.

var v = Vrijeme(15, 22, 33);

var nv = v.minusSati(2);
ispis(nv.sati, ":", nv.minute);
13:22

plusMinuta

The plusMinuta function returns a copy of the calling Vrijeme object with the specified number of minutes added. The original Vrijeme object remains unchanged.

var v = Vrijeme(15, 22, 33);

var nv = v.plusMinuta(23);
ispis(nv.sati, ":", nv.minute);
15:45

minusMinuta

The minusMinuta function returns a copy of the calling Vrijeme object with the specified number of minutes subtracted. The original Vrijeme object remains unchanged.

var v = Vrijeme(15, 22, 33);

var nv = v.minusMinuta(22);
ispis(nv.sati, ":", nv.minute);
15:00

plusSekundi

The plusSekundi function returns a copy of the calling Vrijeme object with the specified number of minutes added. The original Vrijeme object remains unchanged.

var v = Vrijeme(15, 22, 33);

var nv = v.plusSekundi(23);
ispis(nv.sati, ":", nv.minute, ":", nv.sekunde);
15:22:56

minusSekundi

The minusSekundi function returns a copy of the calling Vrijeme object with the specified number of minutes subtracted. The original Vrijeme object remains unchanged.

var v = Vrijeme(15, 22, 33);

var nv = v.minusSekundi(22);
ispis(nv.sati, ":", nv.minute, ":", nv.sekunde);
15:22:11

plusNanoSekundi

The plusNanoSekundi function returns a copy of the calling Vrijeme object with the specified number of nanoseconds added. The original Vrijeme object remains unchanged.

var v = Vrijeme(15, 22, 33);

var nv = v.plusNanoSekundi(23);
ispis(nv.nanosekunde);
23

minusNanoSekundi

The minusNanoSekundi function returns a copy of the calling Vrijeme object with the specified number of nanoseconds subtracted. The original Vrijeme object remains unchanged.

var v = Vrijeme(15, 22, 00);

var nv = v.minusNanoSekundi(22);
ispis(nv.nanosekunde);
38

periodIzmedju

The periodIzmedju function determines how much time has passed between the calling Vrijeme object and the provided other Vrijeme object.

var vj = Vrijeme(12, 30, 0);
var vd = Vrijeme(15, 22, 0);

ispis("12:30", " do ", "15:22", ": ");
ispis(vj.periodIzmedju(vd));
Output:

{ sati: 2, minute: 52, sekunde: 0 }

jePoslije

The jePoslije function determines whether the calling Vrijeme object is after the provided other Vrijeme object.

var t1 = Vrijeme(12, 30, 0);
var t2 = Vrijeme(15, 22, 0);

ispis(t1.jePoslije(t2));
ispis(t2.jePoslije(t1));
Output:

netačno
tačno

jePrije

The jePrije function determines whether the calling Vrijeme object is before the provided other Vrijeme object.

var t1 = Vrijeme(12, 30, 0);
var t2 = Vrijeme(15, 22, 0);

ispis(t1.jePrije(t2));
ispis(t2.jePrije(t1));
Output:

tačno
netačno

naDatum

The naDatum function combines the calling Vrijeme object with a provided Datum object into a new DatumVrijeme object.

var datum = {
  godina: 2023,
  mjesec: 5,
  danMjeseca: 26,
};

var sati = Vrijeme(18, 30, 0);

var dv = sati.naDatum(datum);

ispis(dv.danMjeseca, ".", dv.mjesec, ".", dv.godina);
ispis(dv.sati, ":", dv.minute, ":", dv.sekunde);
Output:

26.5.2023
18:30:00

jednako

The jednako function determines whether the calling Vrijeme object is equal to the provided other Vrijeme object.

var t1 = Vrijeme(12, 30, 0);
var t2 = Vrijeme(15, 22, 0);
var t3 = Vrijeme(15, 22, 0);

ispis(t1.jednako(t2));
ispis(t2.jednako(t3));
Output:

netačno
tačno