Vrijeme
paket "vrijeme";
The vrijeme
package provides a way to work with local time. The package includes the following functions and properties:
- vrijemeSada
- vrijemeIzTeksta
- vrijemePoFormatu
- Vrijeme
All four functions return a Vrijeme
object, which contains the following functions and properties:
- sati
- minute
- sekunde
- nanosekunde
- plusSati
- minusSati
- plusMinuta
- minusMinuta
- plusSekundi
- minusSekundi
- plusNanosekundi
- minusNanosekundi
- periodIzmedju
- jePoslije
- jePrije
- naDatum
- jednako
Package functions
vrijemeSada
The vrijemeSada
function returns a Vrijeme
object representing the current time from the system clock in the default
time-zone.
- takes: no parameters
- returns:
Vrijeme
object representing the current time
- special cases: none
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.
- takes: str -
tekst
to parse - returns:
Vrijeme
object parsed fromstr
- special cases:
- Throws exception if
str
cannot be parsed
- Throws exception if
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.
- takes:
- str -
tekst
to parse - format -
tekst
representing format to parse by
- str -
- returns:
Vrijeme
object parsed fromstr
- special cases:
- Throws exception if
str
cannot be parsed - Throws exception if
format
is not a valid time format
- Throws exception if
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.
- takes:
- hours -
broj
between 0 and 23 - minutes -
broj
between 0 and 59 - seconds -
broj
between 0 and 59
- hours -
- returns:
Vrijeme
object according to the provided hours, minutes and seconds
- special cases:
- Throws exception if
hours
,minutes
, orseconds
is an invalid value
- Throws exception if
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.
- takes:
- hours - number of hours to add (
broj
)
- hours - number of hours to add (
- returns:
- new
Vrijeme
object with the specified number of hours added
- new
- special cases: none
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.
- takes:
- hours - number of hours to subtract (
broj
)
- hours - number of hours to subtract (
- returns:
- new
Vrijeme
object with the specified number of hours subtracted
- new
- special cases: none
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.
- takes:
- minutes - number of minutes to add (
broj
)
- minutes - number of minutes to add (
- returns:
- new
Vrijeme
object with the specified number of minutes added
- new
- special cases: none
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.
- takes:
- minutes - number of minutes to add (
broj
)
- minutes - number of minutes to add (
- returns:
- new
Vrijeme
object with the specified number of minutes subtracted
- new
- special cases: none
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.
- takes:
- seconds - number of seconds to add (
broj
)
- seconds - number of seconds to add (
- returns:
- new
Vrijeme
object with the specified number of seconds added
- new
- special cases: none
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.
- takes:
- seconds - number of seconds to add (
broj
)
- seconds - number of seconds to add (
- returns:
- new
Vrijeme
object with the specified number of seconds subtracted
- new
- special cases: none
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.
- takes:
- nanoseconds - number of nanoseconds to add (
broj
)
- nanoseconds - number of nanoseconds to add (
- returns:
- new
Vrijeme
object with the specified number of nanoseconds added
- new
- special cases: none
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.
- takes:
- nanoseconds - number of nanoseconds to add (
broj
)
- nanoseconds - number of nanoseconds to add (
- returns:
- new
Vrijeme
object with the specified number of nanoseconds subtracted
- new
- special cases: none
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.
- takes:
- other -
Vrijeme
object
- other -
- returns:
Vrijeme
object representing the time passed between callingVrijeme
andother
- special cases: none
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.
- takes:
- other -
Vrijeme
object
- other -
- returns:
logički
tačno
if the callingVrijeme
object is afterother
netačno
otherwise
- special cases: none
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.
- takes:
- other -
Vrijeme
object
- other -
- returns:
logički
tačno
if the callingVrijeme
object is beforeother
netačno
otherwise
- special cases: none
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.
- takes:
- date -
Datum
object
- date -
- returns:
DatumVrijeme
object which combines the callingVrijeme
anddate
- special cases: none
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.
- takes:
- other -
Vrijeme
object
- other -
- returns:
logički
tačno
if the callingVrijeme
object andother
have the same hours, minutes, seconds and nanosecond valuesnetačno
otherwise
- special cases: none
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