Datum
paket "datum";
The datum
package provides a way to work with local dates.
Package functions
datumSada
The datumSada
function returns a Datum
object representing the current date from the system clock in the default time-zone.
- takes: no parameters
- returns:
Datum
object representing the current time
- special cases: none
var now = datumSada(); ispis(now.danMjeseca, ".", now.mjesec, ".", now.godina);
16.5.2023
datumIzTeksta
The datumIzTeksta
function parses a Datum
object out of a provided tekst
in the dd.MM.yyyy
format.
- takes: str -
tekst
to parse - returns:
Datum
object parsed fromstr
- special cases:
- Throws exception if
str
cannot be parsed
- Throws exception if
var date = datumIzTeksta("26.05.2023"); ispis(date.danMjeseca, ".", date.mjesec, ".", date.godina);
26.5.2023
Invalid tekst
example:
var time = datumIzTeksta("31.2.2023");
Error: Cannot parse Datum from tekst "31.2.2023"
datumPoFormatu
The datumPoFormatu
function parses a Datum
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:
Datum
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 date = datumPoFormatu("11/10/2000", "dd/MM/yyyy"); ispis(date.danMjeseca, ".", date.mjesec, ".", date.godina);
11.10.2000
Invalid date example:
var date = datumIzTeksta("96/10/2000", "dd/MM/yyyy");
Error: Cannot parse Datum from tekst "96/10/2000".
Invalid format example:
var date = datumIzTeksta("11/10/2000", "yy/YY/yyyy");
Error: 'yy/YY/yyyy' is not a valid time format.
Datum constructor
You can use the Datum constructor to construct a Datum object by providing a value for day, month and year.
- takes:
- day -
broj
between 1 and 31 - month -
broj
between 1 and 12 - year -
broj
between -999999999 and 999999999
- day -
- returns:
Datum
object according to the provided day, month and year
- special cases:
- Throws exception if
year
,month
, orday
is an invalid value
- Throws exception if
var date = Datum(28, 8, 2023); ispis(date.danMjeseca, ".", date.mjesec, ".", date.godina);
28.8.2023
Datum object
godina
The godina
property is a broj
holding the year part of the Datum object.
var date = Datum(11,10,2023); ispis(date.godina);
Output:
2000
mjesec
The godina
property is a broj
holding the year part of the Datum object.
var date = Datum(11,10,2023); ispis(date.mjesec);
Output:
10
danGodine
The danGodine
property is a broj
holding the day-of-year field of the Datum object.
var date = Datum(11,10,2023); ispis(date.danGodine);
Output:
284
danMjeseca
The danMjeseca
property is a broj
holding the day-of-month field of the Datum object. This is the day part of the date
you will usually need.
var date = Datum(11,10,2023); ispis(date.danMjeseca);
Output:
11
danSedmice
The danSedmice
property is a broj
holding the day-of-week field of the Datum object, starting from 1 for Monday.
var date = Datum(11,10,2000); ispis(date.danSedmice);
Output:
3
plusDana
The plusDana
function returns a copy of the calling Datum
object with the specified number of days added. The original
Datum
object remains unchanged.
- takes:
- days - number of days to add (
broj
)
- days - number of days to add (
- returns:
- new
Datum
object with the specified number of days added
- new
- special cases: none
var date = Datum(11,10,2000); var nd = date.plusDana(10); ispis(date.danMjeseca, ".", date.mjesec, ".", date.godina);
21.10.2000
minusDana
The minusDana
function returns a copy of the calling Datum
object with the specified number of days subtracted.
The original Datum
object remains unchanged.
- takes:
- days - number of days to subtract (
broj
)
- days - number of days to subtract (
- returns:
- new
Datum
object with the specified number of days subtracted
- new
- special cases: none
var date = Datum(11,10,2000); var nd = date.minusDana(10); ispis(date.danMjeseca, ".", date.mjesec, ".", date.godina);
1.10.2000
plusSedmica
The plusSedmica
function returns a copy of the calling Datum
object with the specified number of weeks added. The original
Datum
object remains unchanged.
- takes:
- weeks - number of weeks to add (
broj
)
- weeks - number of weeks to add (
- returns:
- new
Datum
object with the specified number of weeks added
- new
- special cases: none
var date = Datum(11,10,2000); var nd = date.plusSedmica(2); ispis(date.danMjeseca, ".", date.mjesec, ".", date.godina);
25.10.2000
minusSedmica
The minusSedmica
function returns a copy of the calling Datum
object with the specified number of weeks subtracted.
The original Datum
object remains unchanged.
- takes:
- weeks - number of weeks to subtract (
broj
)
- weeks - number of weeks to subtract (
- returns:
- new
Datum
object with the specified number of weeks subtracted
- new
- special cases: none
var date = Datum(11,10,2000); var nd = date.minusSedmica(1); ispis(date.danMjeseca, ".", date.mjesec, ".", date.godina);
4.10.2000
plusMjeseci
The plusMjeseci
function returns a copy of the calling Datum
object with the specified number of months added.
The original Datum
object remains unchanged.
- takes:
- months - number of months to add (
broj
)
- months - number of months to add (
- returns:
- new
Datum
object with the specified number of months added
- new
- special cases: none
var date = Datum(11,10,2000); var nd = date.plusMjeseci(2); ispis(date.danMjeseca, ".", date.mjesec, ".", date.godina);
11.12.2000
minusMjeseci
The minusMjeseci
function returns a copy of the calling Datum
object with the specified number of months added.
The original Datum
object remains unchanged.
- takes:
- months - number of months to add (
broj
)
- months - number of months to add (
- returns:
- new
Datum
object with the specified number of months added
- new
- special cases: none
var date = Datum(11,10,2000); var nd = date.minusMjeseci(2); ispis(date.danMjeseca, ".", date.mjesec, ".", date.godina);
11.8.2000
plusGodina
The plusGodina
function returns a copy of the calling Datum
object with the specified number of years added.
The original Datum
object remains unchanged.
- takes:
- years - number of years to add (
broj
)
- years - number of years to add (
- returns:
- new
Datum
object with the specified number of years added
- new
- special cases: none
var date = Datum(11,10,2000); var nd = date.plusGodina(23); ispis(date.danMjeseca, ".", date.mjesec, ".", date.godina);
11.10.2023
minusGodina
The minusGodina
function returns a copy of the calling Datum
object with the specified number of years subtracted.
The original Datum
object remains unchanged.
- takes:
- years - number of years to subtract (
broj
)
- years - number of years to subtract (
- returns:
- new
Datum
object with the specified number of years subtracted
- new
- special cases: none
var date = Datum(11,10,2000); var nd = date.minusGodina(20); ispis(date.danMjeseca, ".", date.mjesec, ".", date.godina);
11.10.1980
periodIzmedju
The periodIzmedju
function determines how much time has passed between the calling Datum
object and the provided
other Datum
object.
- takes:
- other -
Datum
object
- other -
- returns:
Datum
object representing the time passed between callingDatum
andother
- special cases: none
var d1 = Datum(11, 10, 2000); var d2 = Datum(14, 1, 2003); ispis(d1.periodIzmedju(d2));
Output: { godine: 2, mjeseci: 3, dani: 3 }
jePoslije
The jePoslije
function determines whether the calling Datum
object is after the provided
other Datum
object.
- takes:
- other -
Datum
object
- other -
- returns:
logički
tačno
if the callingDatum
object is afterother
netačno
otherwise
- special cases: none
var d1 = Datum(11, 10, 2000); var d2 = Datum(14, 1, 2003); ispis(d1.jePoslije(d2)); ispis(d2.jePoslije(d1));
Output: netačno tačno
jePrije
The jePrije
function determines whether the calling Datum
object is before the provided
other Datum
object.
- takes:
- other -
Datum
object
- other -
- returns:
logički
tačno
if the callingDatum
object is beforeother
netačno
otherwise
- special cases: none
var d1 = Datum(11, 10, 2000); var d2 = Datum(14, 1, 2003); ispis(d1.jePrije(d2)); ispis(d2.jePrije(d1));
Output:
tačno
netačno
jednako
The jednako
function determines whether the calling Datum
object is equal to the provided
other Datum
object.
- takes:
- other -
Datum
object
- other -
- returns:
logički
tačno
if the callingDatum
object andother
have the same year, month, and day valuesnetačno
otherwise
- special cases: none
var t1 = Datum(11, 10, 2000); var t2 = Datum(11, 10, 2023); var t3 = Datum(14, 1, 2003); var t4 = Datum(14, 1, 2003); ispis(t1.jednako(t2)); ispis(t3.jednako(t4));
Output: netačno tačno