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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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