Code covered by the BSD License

WETON: Javanese calendar

François Beauducel (view profile)

24 Mar 2011 (Updated )

Computes "weton" dates in the Javanese calendar

weton.m
```function XX = weton(year,month,day,n)
%WETON	Javanese calendar / Wetonan.
%	WETON without input argument returns the javanese date for today,
%	in the form:
%	   DINAPITU PASARAN DINA WULAN T TAUN WINDU KURUP, DAY MONTH YEAR (DINO MULYO)
%	where:
%	   DINAPITU = day name in the Gregorian/Islamic week (7-day cycle)
%	   PASARAN = Javanese day name (in the 5-day cycle)
%	   DINA = day number in the Javanese month (1 to 29 or 30)
%	   WULAN = Javanese month name
%	   T = Javanese year number (starts on 1555)
%	   TAUN = Javanese year name (8 different, 12-Wulan cycle)
%	   WINDU = Javanese "decade" name (4 different, 8-Taun cycle)
%	   KURUP = Javanese "century" name (7 different, 120-Taun cycle)
%	   DINO MULYO = "noble day" name (if necessary)
%
%	WETON(YEAR,MONTH,DAY) returns the javanese date corresponding to
%	YEAR-MONTH-DAY in the Gregorian calendar.
%
%	WETON(YEAR,MONTH,DAY,N) returns the list of your N first javanese
%	birthdays (from the 35-day "Weton" cycle). Example: if you are born
%	on Dec 3, 1968 then
%	   weton(1968,12,3,10)
%	returns your 10 first Wetons. Thanks to the Matlab flexibility,
%	   weton(1968,12,3+35*(0:10))
%	will do the same job...
%
%	WETON(T) uses date T which can be Matlab date scalar, vector, matrix
%	or any valid string for DATENUM function. Examples:
%	   weton(719135)
%	   weton('3-Dec-1968')
%	   weton([1968,12,3])
%	all return the string
%	   'Selasa Kliwon 12 Pasa 1900 Eh Adi Arbangiyah, 3 Desember 1968 (HANGGARA ASIH)'
%
%	WETON(YEAR,MONTH) returns a javanese calendar for YEAR and MONTH in a
%	table combining the 5-day "Pasaran" cycle and 7-day Gregorian week.
%	Example: weton(1994,4) returns the following:
%
%	------------------ WETONAN BULAN APRIL 1994 ------------------
%	Awal:  Jemuwah Kliwon 19 Sawal 1926 J Sancaya Salasiyah,  1 April 1994
%	Akhir: Setu Wag 19 Dulkangidah 1926 J Sancaya Salasiyah, 30 April 1994
%	------------------------------------------------------------------
%                   Senn   Selasa  Rebo    Kemis   Jemuwah Setu    Minggu
%	   Pon      04      19       -      14      29      09      24
%	  Wag      25      05      20       -      15      30      10
%	Kliwon      11      26      06      21      01      16       -
%	  Legi       -      12      27      07      22      02      17
%	Pahing      18       -      13      28      08      23      03
%
%	where "Awal:" is the first day of the month, "Akhir:" the last one.
%
%	X = WETON(...) returns a structure X with corresponding fields instead of
%	displaying strings. To display full dates, use
%	   cat(1,char(X.weton))
%
%	Author: Mas Franois Beauducel
%	Created: 1999-01-27 (Rebo Pahing)
%	Updated: 2011-03-26 (Setu Pon)

%
%	Redistribution and use in source and binary forms, with or without
%	modification, are permitted provided that the following conditions are
%	met:
%
%	   * Redistributions of source code must retain the above copyright
%	     notice, this list of conditions and the following disclaimer.
%	   * Redistributions in binary form must reproduce the above copyright
%	     notice, this list of conditions and the following disclaimer in
%	     the documentation and/or other materials provided with the distribution
%
%	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
%	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
%	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
%	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
%	LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
%	CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
%	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
%	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
%	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
%	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
%	POSSIBILITY OF SUCH DAMAGE.

error(nargchk(0,4,nargin))

% origin date = 1 Sura 1555 Alip Kuntara
t0 = datenum(1633,7,8);
taun0 = 1555;

% 24 March 1936 = Selasa Pon 1 Sura 1867 Alip Adi Salasiyah (ASAPON)
%+ start a change of Wulan length in each Tahun
t1 = datenum(1936,3,24);

% Pasaran = 5 day-names of javanese week
pasaran = {'Pon','Wag','Kliwon','Legi','Pahing'};

% Minggu = 7 day-names of gregorian week
minggu = {'Senn','Selasa','Rebo','Kemis','Jemuwah','Setu','Minggu'};

% Bulan = Gregorian month names
bulan = {'Januari','Februari','Maret','April','Mei','Juni', ...
'Juli','Agustus','September','Oktober','November','Desember'};

% Wulan = Javanese month names (1/12 of Moon year)
'Rejeb','Ruwah','Pasa','Sawal','Dulkangidah','Besar'};

% Tahun = Moon year, alternate 354 and 355-day length (depending on wulan Besar length)
taun = {'Alip','Eh','Jimawal','J','Dal','B','Wawu','Jimakhir'};

% Windu = 8-taun cycle = 81-wetonan = 2835-day

% for each Windu, determine a vector for number of days per Tahun
w354 = 29+[1,0,1,0,1,0,1,0,1,0,1,0]';	% Tahun 1,3,5,6,7
w355 = 29+[1,0,1,0,1,0,1,0,1,0,1,1]';	% Tahun 2,4,8
wdal = 29+[1,1,0,0,0,0,1,0,1,0,1,1]';	% Tahun 5 (Dal) before 1936-2-26

% Windu matrix (size 12x8) of Wulan x Tahun
hw0 = [w354,w355,w354,w355,wdal,w354,w354,w355];	% before 1936-3-26
hw1 = [w354,w355,w354,w355,w354,w354,w354,w355];	% since 1936-3-26

% Kurup = 120-taun cycle = 15-windu = 42524-day (1 day must be substracted)

if nargin == 2 & (~isnumeric(month) | ~isnumeric(year) | numel(month) > 1 | numel(year) > 1)
error('YEAR and MONTH arguments must be scalar.')
end

if nargin > 2 & ~isnumeric(day)
error('DAY argument must be numeric.')
end

if nargin == 4 & (~isnumeric(n) |  numel(n) > 1)
error('N argument must be scalar.')
end

switch nargin
case 1
dt = datenum(year);
case 2
% calculates the number of days in month using DATEVEC
ct = datevec(datenum(year,month,1:31));
year = ct(1,1);
month = ct(1,2);
day = max(ct(:,3));
dt = datenum(year,month,1:day);
case 3
dt = datenum(year,month,day);
case 4
dt = datenum(year,month,day) + 35*(0:n)';
otherwise
dt = now;
end
dt = floor(dt);

if any(dt < t0)
warning('Some dates are unvalid (before %s)',datestr(t0));
end

s = cell(size(dt));
for i = 1:length(dt)
ct = datevec(dt(i));
dti = dt(i) - t0;
dti = dti + floor(dti/(15*81*7*5 - 1));
% relative date into the Windu
dw = mod(dti,81*7*5) + 1;
if dt(i) < t1
% finds the Wulan and Tahun into the table of Windu
k = find(cumsum(hw0(:)) >= dw);
[w,t] = ind2sub(size(hw0),k(1));
% computes the day number
if k(1) == 1
dina = dw;
else
dina = dw - sum(hw0(1:(k(1)-1)));
end
else
% finds the Wulan and Tahun into the table of Windu
k = find(cumsum(hw1(:)) >= dw);
[w,t] = ind2sub(size(hw1),k(1));
% computes the day number
if k(1) == 1
dina = dw;
else
dina = dw - sum(hw1(1:(k(1)-1)));
end
end
% day of the week
m = mod(dt(i) + 4,7) + 1;
X(i).dina = minggu{m};
% pasaran
p = mod(dt(i) + 2,5) + 1;
X(i).pasaran = pasaran{p};
X(i).date = dt(i);
X(i).d = dina;
X(i).wulan = wulan{w};
X(i).t = floor(dti/(81*7*5))*8 + t + taun0 - 1;
X(i).taun = taun{t};
X(i).windu = windu{mod(floor(dti/(81*7*5)) + 1,4) + 1};
X(i).kurup = kurup{mod(floor(dti/(15*81*7*5)),7) + 1};
X(i).day = ct(3);
X(i).month = bulan{ct(2)};
X(i).year = ct(1);

% "Dino Mulyo": noble days
mulyo = '';
if dina == 1 & w == 1
mulyo = 'Satu Suro';
end
if t == 1 & w == 3 & p == 2
mulyo = 'Aboge';
end
if t == 5 & m == 6 & p == 4
mulyo = 'Daltugi';
end
if m == 2 & p == 3
mulyo = 'Hanggara Asih';
end
if m == 5 & p == 4
mulyo = 'Dino Purnomo';
end
X(i).mulyo = mulyo;

ss = sprintf('%s %s %2d %1s %4d %s %s %s, %2d %s %4d', ...
minggu{m},pasaran{p}, ...
dina, wulan{w}, floor(dti/(81*7*5))*8 + t + taun0 - 1, taun{t}, ...
windu{mod(floor(dti/(81*7*5 - 1/15)) + 1,4) + 1}, ...
kurup{mod(floor(dti/(15*81*7*5 - 1)),7) + 1}, ...
ct(3),bulan{ct(2)},ct(1));
if ~isempty(mulyo)
ss = sprintf('%s (%s)',ss,upper(mulyo));
end
s{i} = ss;
X(i).weton = ss;
end

if nargin == 2
s = cell(10,1);
ct = datevec(dt(1));

kal = cell(5,7);
kal(:) = {' -'};
for i = 1:day
kal{mod(dt(i)+2,5)+1,mod(dt(i)+4,7)+1} = sprintf('%02d',i);
end
s{1} = sprintf('------------------ WETONAN BULAN %s %d ------------------', ...
upper(bulan{ct(2)}),ct(1));
s{2} = sprintf('Awal:  %s',X(1).weton);
s{3} = sprintf('Akhir: %s',X(end).weton);
s{4} = sprintf('%s',repmat('-',66,1));
s{5} = sprintf('            %s',[char(minggu),32*ones(7,1)]');
for i = 1:5
s{5+i} = [sprintf('%6s',pasaran{i}),sprintf('%8s',kal{i,:})];
end
end

if nargout == 0
disp(char(s));
else
XX = X;
end
```