1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
212
  
213
  
214
  
215
  
216
  
217
  
218
  
219
  
220
  
221
  
222
  
223
  
224
  
225
  
226
  
227
  
228
  
229
  
230
  
231
  
232
  
233
  
234
  
235
  
236
  
237
  
238
  
239
  
240
  
241
  
242
  
243
  
244
  
245
  
246
  
247
  
248
  
249
  
250
  
251
  
252
  
253
  
254
  
255
  
256
  
257
  
258
  
259
  
260
  
261
  
262
  
263
  
264
  
265
  
266
  
267
  
268
  
269
  
270
  
271
  
272
  
273
  
274
  
275
  
276
  
277
  
278
  
279
  
280
  
281
  
282
  
283
  
284
  
285
  
286
  
287
  
288
  
289
  
290
  
291
  
292
  
293
  
294
  
295
  
296
  
297
  
298
  
299
  
300
  
301
  
302
  
303
  
304
  
305
  
306
  
307
  
308
  
309
  
310
  
311
  
312
  
313
  
314
  
315
  
316
  
317
  
318
  
319
  
320
  
321
  
322
  
323
  
324
  
325
  
326
  
327
  
328
  
329
  
330
  
331
  
332
  
333
  
334
  
335
  
336
  
337
  
338
  
339
  
340
  
341
  
342
  
343
  
344
  
345
  
346
  
347
  
348
  
349
  
350
  
351
  
352
  
353
  
354
  
355
  
356
  
357
  
358
  
359
  
360
  
361
  
362
  
363
  
364
  
365
  
366
  
367
  
368
  
369
  
370
  
371
  
372
  
373
  
374
  
375
  
376
  
377
  
378
  
379
  
380
  
381
  
382
  
383
  
384
  
385
  
386
  
387
  
388
  
389
  
390
  
391
  
392
  
393
  
394
  
395
  
396
  
397
  
398
  
399
  
400
  
401
  
402
  
403
  
404
  
405
  
406
  
407
  
408
  
409
  
410
  
411
  
412
  
413
  
414
  
415
  
416
  
417
  
418
  
419
  
420
  
421
  
422
  
423
  
424
  
425
  
426
  
427
  
428
  
429
  
430
  
431
  
432
  
433
  
434
  
435
  
436
  
437
  
438
  
439
  
440
  
441
  
442
  
443
  
444
  
445
  
446
  
447
  
448
  
449
  
450
  
451
  
452
  
453
  
454
  
455
  
456
  
457
  
458
  
459
  
460
  
461
  
462
  
463
  
464
  
465
  
466
  
467
  
468
  
469
  
470
  
471
  
472
  
473
  
474
  
475
  
476
  
477
  
478
  
479
  
480
  
481
  
482
  
483
  
484
  
485
  
486
  
487
  
488
  
489
  
490
  
491
  
492
  
493
  
494
  
495
  
496
  
497
  
498
  
499
  
500
  
501
  
502
  
503
  
504
  
505
  
506
  
507
  
508
  
509
  
510
  
511
  
512
  
513
  
514
  
515
  
516
  
517
  
518
  
519
  
520
  
521
  
522
  
523
  
524
  
525
  
526
  
527
  
528
  
529
  
530
  
531
  
532
  
533
  
534
  
535
  
536
  
537
  
538
  
539
  
540
  
541
  
542
  
543
  
544
  
545
  
546
  
547
  
548
  
549
  
550
  
551
  
552
  
553
  
554
  
555
  
556
  
557
  
558
  
559
  
560
  
561
  
562
  
563
  
564
  
565
  
566
  
567
  
568
  
569
  
570
  
571
  
572
  
573
  
574
  
575
  
576
  
577
  
578
  
579
  
580
  
581
  
582
  
583
  
584
  
585
  
586
  
587
  
588
  
589
  
590
  
591
  
592
  
593
  
594
  
595
  
596
  
597
  
598
  
599
  
600
  
601
  
602
  
603
  
604
  
605
  
606
  
607
  
608
  
609
  
610
  
611
  
612
  
613
  
614
  
615
  
616
  
617
  
618
  
619
  
620
  
621
  
622
  
623
  
624
  
625
  
626
  
627
  
628
  
629
  
630
  
631
  
632
  
633
  
634
  
635
  
636
  
637
  
638
  
639
  
640
  
641
  
642
  
643
  
644
  
645
  
646
  
647
  
648
  
649
  
650
  
651
  
652
  
653
  
654
  
655
  
656
  
#pike __REAL_VERSION__ 
 
//! This is the Badi calendar, 
//! used in the Baha'i religion. 
 
inherit Calendar.YMD:YMD; 
 
#include "constants.h" 
 
string calendar_name() { return "Badi"; } 
 
private protected mixed __initstuff=lambda() 
{ 
   f_week_day_shortname_from_number="badi_week_day_shortname_from_number"; 
   f_week_day_name_from_number="badi_week_day_name_from_number"; 
   f_year_name_from_number="badi_year_name_from_number"; 
   f_week_day_number_from_name="badi_week_day_number_from_name"; 
 
   f_month_day_name_from_number="badi_month_day_name_from_number"; 
   f_month_name_from_number="badi_month_name_from_number"; 
   f_month_shortname_from_number="badi_month_shortname_from_number"; 
   f_month_number_from_name="badi_month_number_from_name"; 
   f_week_name_from_number="week_name_from_number"; 
   f_year_number_from_name="badi_year_number_from_name"; 
   dwim_year=([ "past_lower":0, "past_upper":0, 
                "current_century":0, "past_century":0 ]); 
}(); 
 
protected int year_leap_year(int y) 
{ 
   // the beginning of the year is the day of the spring equinox 
   // leap years are those where an extra day is needed to get up to the next 
   // spring equinox. 
   // for now this rule is not in effect and the start of the year is march 
   // 21st. leap years are thus compatible with the gregorian calendar for the 
   // time being. 
   y+=1844; 
   return (!(((y)%4) || (!((y)%100) && ((y)%400)))); 
} 
 
// [y,yjd] 
protected array year_from_julian_day(int jd) 
{ 
   // in order to avoid coming up with a formula for leapyears in the bahai 
   // calendar we add the necessary offsets to the data so we can use the take 
   // the gregorian formula 
   // gregorian year starts 286 days later march 21st -> january 1st 
   int d=jd+286-1721426; 
 
   int century=(4*d+3)/146097; 
   int century_jd=(century*146097)/4; 
   int century_day=d-century_jd; 
   int century_year=(100*century_day+75)/36525; 
 
   return 
   ({ 
      (century*100+century_year+1)-1844, // but 1844 years earlier 
      1721426-286+century_year*365+century_year/4+century_jd, 
   }); 
} 
 
protected int julian_day_from_year(int y) 
{ 
   // FIXME: verify for leapyears (esp: 56 (1900) and 100, ...) 
   // same as above 
   y+=1843; // above we are adding days and subtracting years, 
            // going back we need to subtract days and add years. 
   return 1721426-286+y*365+y/4-y/100+y/400; 
} 
 
protected int compat_week_day(int n) 
{ 
   // this is specific to the gregorian calendar. 
   // we just stick with the value as it is 
   return n; 
} 
 
protected array(int) year_month_from_month(int y,int m) 
{ 
// [y,m,ndays,myd] 
 
   y+=(m-1)/19; 
   m=1+(m-1)%19; 
 
   switch (m) 
   { 
      case 1..17: return ({y,m,19,(m-1)*19+1}); 
      case    18: return ({y,m,23+year_leap_year(y),(m-1)*19+1}); 
      case    19: return ({y,m,19,347+year_leap_year(y)}); 
   } 
 
   error("Month out of range.\n"); 
} 
 
protected array(int) month_from_yday(int y,int yd) 
{ 
// [month,day-of-month,ndays,month-year-day] 
   if (yd<1) 
     return month_from_yday(--y, yd+365+year_leap_year(y)); 
   int ly = year_leap_year(y); 
   switch (yd) 
   { 
      case 1..323: return ({(yd+18)/19, (yd+18)%19+1, 19, ((yd+18)/19-1)*19+1}); 
      case 324..342:   return ({18, (yd+18)%19+1, 23+ly, ((yd+18)/19-1)*19+1 }); 
      case 343..346:   return ({18, yd%19+19, 23+ly, ((yd)/19-1)*19+1 }); 
      case 347: if(ly) return ({18, yd%19+19, 23+ly, ((yd)/19-1)*19+1 }); 
      case 348..365:   return ({19, yd-346-ly, 19, 347+ly}); 
      case 366: if(ly) return ({19, yd-346-ly, 19, 347+ly}); 
   } 
   error("yday out of range.\n"); 
} 
 
protected array(int) week_from_julian_day(int jd) 
{ 
// [year,week,day-of-week,ndays,week-julian-day] 
 
   [int y,int yjd]=year_from_julian_day(jd); 
   int yday=jd-yjd+1; 
   int wjd=jd-(jd+2)%7;  // +2 is the offset from the julian day week 
                         // starting on monday. 
 
   int k=4+(yjd-2)%7; 
   int w=(yday+k-1)/7; 
 
   //werror("jd %d: y%O yjd%O yday%O, k%O w%O wjd%O, wd%O:%O\n",jd,y,yjd,yday,k,w,wjd, 1+(jd+2)%7, 1+(1+yjd+yday)%7); 
 
   if (!w) 
   { 
// handle the case that the day is in the previous year; 
// years previous to years staring on saturday, 
//              ...  and leap years starting on sunday 
      y--; 
      w=52+( (k==4) || ( (k==5) && year_leap_year(y) ) ); 
   } 
   else if (w==53 && k>=6-year_leap_year(y) && k<10-year_leap_year(y)) 
   { 
// handle the case that the week is in the next year 
      y++; 
      w=1; 
   } 
 
   //werror("jd %d: y%O yjd%O yday%O, k%O w%O wjd%O, wd%O:%O\n",jd,y,yjd,yday,k,w,wjd, 1+(jd+2)%7, 1+(1+yjd+yday)%7); 
   return ({y,w,1+(1+yjd+yday)%7,7,wjd}); 
} 
 
protected array(int) week_from_week(int y,int w) 
{ 
// [year,week,1 (wd),ndays,week-julian-day] 
 
   int yjd=julian_day_from_year(y); 
   int wjd=-6+yjd-(yjd+3)%7; 
//   int wjd=-7+yjd-(yjd+2)%7; 
 
   werror("%t: %O, %O, %O, %O\n", this, y, w, wjd, wjd+w*7); 
   if (w<1 || w>52) // may or may not be out of this year 
      return week_from_julian_day(wjd+w*7); 
 
   return ({y,w,1,7,wjd+w*7}); 
//   fixme 
} 
 
// identical to gregorian 
protected int year_remaining_days(int y,int yday) 
{ 
   return 365+year_leap_year(y)-yday; 
} 
 
//! @decl int daystart_offset() 
//!     Returns the offset to the start of the time range object 
//! 
int daystart_offset() 
{ 
  return -21600; // 6 hours earlier 
} 
 
class cFraction 
{ 
   inherit YMD::cFraction; 
 
   TimeRange make_base() 
   { 
      base=Day("unix_r",ux-daystart_offset(),rules); 
      if (len) base=base->range(Day("unix_r",ux-daystart_offset()+len,rules)); 
      return base; 
   } 
 
   protected void make_local() 
   { 
      ::make_local(); 
      ls+=daystart_offset(); 
   } 
} 
 
class cSecond 
{ 
   inherit YMD::cSecond; 
 
   TimeRange make_base() 
   { 
      base=Day("unix_r",ux-daystart_offset(),rules); 
      if (len) base=base->range(Day("unix_r",ux-daystart_offset()+len,rules)); 
      return base; 
   } 
 
   protected void make_local() 
   { 
      ::make_local(); 
      ls+=daystart_offset(); 
   } 
} 
 
class cMinute 
{ 
   inherit YMD::cMinute; 
 
   TimeRange make_base() 
   { 
      base=Day("unix_r",ux-daystart_offset(),rules); 
      if (len) base=base->range(Day("unix_r",ux-daystart_offset()+len,rules)); 
      return base; 
   } 
 
   protected void make_local() 
   { 
      ::make_local(); 
      ls+=daystart_offset(); 
   } 
 
/* 
   int unix_time() 
   { 
      int offset=daystart_offset(); 
      int minuteoffset=offset%60; 
      if(houroffset>30) 
        offset+=60-minuteoffset; 
      else 
        offset-=minuteoffset; 
      return ::unix_time()+offset; 
   } 
*/ 
} 
 
class cHour 
{ 
   inherit YMD::cHour; 
 
   TimeRange make_base() 
   { 
      base=Day("unix_r",ux-daystart_offset(),rules); 
      if (len) base=base->range(Day("unix_r",ux-daystart_offset()+len,rules)); 
      return base; 
   } 
 
   protected void make_local() 
   { 
      ::make_local(); 
      ls+=daystart_offset(); 
   } 
 
/* 
   int unix_time() 
   { 
      int houroffset=daystart_offset()%3600; 
      if(houroffset>1800) 
        houroffset-=3600; 
      int ux=::unix_time(); 
      werror("cHour:%d:%d:%d\n", daystart_offset(), houroffset, ux); 
      return ux-houroffset; 
   } 
*/ 
} 
 
class cDay 
{ 
   inherit YMD::cDay; 
 
   void create_unixtime_default(int unixtime) 
   { 
      ::create_unixtime_default(unixtime-daystart_offset()); 
   } 
 
   string month_name() 
   { 
      if (md > 19) 
        return rules->language[f_month_name_from_number](0); 
      else return ::month_name(); 
   } 
 
   string month_shortname() 
   { 
      if (md > 19) 
        return rules->language[f_month_shortname_from_number](0); 
      else return ::month_shortname(); 
   } 
 
   int unix_time() 
   { 
      return ::unix_time()+daystart_offset(); 
   } 
 
   int number_of_months() 
   { 
      if (n<=1) return 1; 
      if (m==CALUNKNOWN) make_month(); 
      [int zy,int zyjd]=year_from_julian_day(jd+n-1); 
      [int zm,int zmd,int znd,int zmyd]=month_from_yday(zy,jd+n-zyjd); 
      return zm-m+1+(zy-y)*19; 
   } 
 
   string nice_print() 
   { 
      if (m==CALUNKNOWN) make_month(); 
      if (wd==CALUNKNOWN) make_week(); 
      return 
         sprintf("%s %s %s(%d) %s", 
                 week_day_shortname(), 
                 month_day_name(),month_shortname(), month_no(), 
                 year_name()); 
   } 
} 
 
class cWeek 
{ 
   inherit YMD::cWeek; 
 
   // identical to gregorian 
   protected int weeks_to_week(int y2,int w2) 
   { 
      [int y3,int w3,int wd2,int nd2,int jd2]=week_from_week(y2,w2); 
      werror("%t: %O, %O, %O, %O, %O\n", this, y2, w2, jd2, jd, (jd2-jd)/7); 
      return (jd2-jd)/7; 
   } 
 
   int unix_time() 
   { 
      return ::unix_time()+daystart_offset(); 
   } 
 
   int number_of_days() 
   { 
      return 7*n; 
   } 
} 
 
class cMonth 
{ 
   inherit YMD::cMonth; 
 
   protected int months_to_month(int y2,int m2) 
   { 
      return (y2-y)*19+(m2-m); 
   } 
 
   int unix_time() 
   { 
      return ::unix_time()+daystart_offset(); 
   } 
 
   string nice_print() 
   { 
      return sprintf("%s(%d) %s", month_name(), month_no(), year_name()); 
   } 
 
 
   // identical to gregorian 
   TimeRange place(TimeRange what,int|void force) 
   { 
      if (what->is_day) 
      { 
         int wmd=what->month_day(); 
         if (md==CALUNKNOWN) make_month(); 
         if (what->m==2 && m==2 && wmd>=24) 
         { 
            int l1=year_leap_year(what->y); 
            int l2=year_leap_year(y); 
            if (l1||l2) 
            { 
               if (l1 && wmd==24) 
                  if (l2) wmd=24; 
                  else { if (!force) return 0; } 
               else 
               { 
                  if (l1 && wmd>24) wmd--; 
                  if (l2 && wmd>24) wmd++; 
               } 
            } 
         } 
         if (!force && wmd>number_of_days()) return 0; 
         return Day("ymd_yd",rules,y,yjd,jd+wmd-1,yd+wmd-1,what->n); 
      } 
 
      return ::place(what); 
   } 
} 
 
class cYear 
{ 
   inherit YMD::cYear; 
 
   // identical to gregorian 
   int number_of_days() 
   { 
      switch (n) 
      { 
         case 0: return 0; 
         case 1: return 365+leap_year(); 
         default: 
            return julian_day_from_year(y+n)-yjd; 
      } 
   } 
 
   // identical to gregorian 
   int number_of_weeks() 
   { 
      if (!n) return 1; 
      if (n==1) return 53+(yjd%7==5 && leap_year()); 
      return 
         Week("julian",jd) 
         ->range(Week("julian",julian_day_from_year(y+n)-1)) 
         ->number_of_weeks(); 
   } 
 
   int number_of_months() 
   { 
      return 19*n; 
   } 
 
   int unix_time() 
   { 
      return ::unix_time()+daystart_offset(); 
   } 
 
   // identical to gregorian 
   TimeRange place(TimeRange what,void|int force) 
   { 
      if (what->is_day) 
      { 
         int yd=what->yd; 
         if (yd>=55) 
            switch (year_leap_year(what->y)*10+year_leap_year(y)) 
            { 
               case 00: 
               case 11: 
                  break; 
               case 10: /* from leap to non-leap */ 
                  if (yd==55 && !force) return 0; // not this year 
                  yd--; 
                  break; 
               case 01: /* from non-leap to leap */ 
                  yd++; 
                  break; 
            } 
         return Day("ymd_yd",rules,y,yjd,yjd+yd-1,yd,what->n); 
      } 
 
      return ::place(what); 
   } 
 
   Vahid vahid(void|int m) 
   { 
      if (!m || (!n&&m==-1)) 
         return Vahid("ymd_yn",rules,y,1); 
 
      if (m<0) m=number_of_vahids()+m; 
 
      if (m<2) return Vahid("ymd_yn",rules,y,1); 
 
      error("not in range (Vahid 0..%d exist)\n", 
            number_of_vahids()-1); 
   } 
 
   int number_of_vahids() 
   { 
     return 0; 
   } 
} 
 
//! 
class Vahid 
{ 
   inherit YMD; 
   constant is_vahid=1; 
   int v;   // vahid 
   int vjd; // julian day of the first day of the vahid 
 
   protected void create(mixed ...args) 
   { 
      if (!sizeof(args)) 
      { 
         create_now(); 
         v=y/19+1; 
         y=v*19-18; 
         return; 
      } 
      else switch (args[0]) 
      { 
         case "ymd_v": 
            rules=args[1]; 
            v=args[2]; 
            n=args[3]; 
            jd=vjd=julian_day_from_vahid(v); 
            m=md=w=wd=CALUNKNOWN; 
            return; 
         case "ymd_yn": 
            rules=args[1]; 
            y=args[2]; 
            n=args[3]; 
            m=md=w=wd=CALUNKNOWN; 
            yd=1; 
            v=y/19+1; 
            jd=vjd=julian_day_from_vahid(v); 
            return; 
     } 
   } 
 
   int julian_day_from_vahid(int v) 
   { 
     return julian_day_from_year(v*19-18); 
   } 
 
   void create_julian_day(int|float _jd) 
   { 
      [y,yjd]=year_from_julian_day((int)_jd); 
      [v,vjd]=vahid_from_julian_day((int)_jd); 
      jd=vjd; 
      n=1; 
      md=yd=m=1; 
      wd=w=CALUNKNOWN; // unknown 
   } 
 
   array(int) vahid_from_julian_day(int _jd) 
   { 
      [int _y, int _yjd]=year_from_julian_day(_jd); 
      return ({ _y/19+1, julian_day_from_year((_y/19+1)*19-18) }); 
   } 
 
   int unix_time() 
   { 
      return ::unix_time()+daystart_offset(); 
   } 
 
   string vahid_name() 
   { 
      return sprintf("v%d", v); 
   } 
 
   protected string _sprintf(int t) 
   { 
      switch (t) 
      { 
         case 'O': 
//            if (n!=1) 
//               return sprintf("Vahid(%s)",nice_print_period()); 
            return sprintf("Vahid(%s)",nice_print()); 
         case 't': 
            return "Calendar."+calendar_name()+".Vahid"; 
         default: 
            return ::_sprintf(t); 
      } 
   } 
 
   string nice_print() 
   { 
      return vahid_name(); 
   } 
 
//! @decl Year year() 
//! @decl Year year(int n) 
//! @decl Year year(string name) 
//!     Return a year in the vahid by number or name: 
//! 
//!     @tt{vahid->year("Alif")@} 
   cYear year(int|string ... yp) 
   { 
      int num; 
      if (sizeof(yp) && 
          stringp(yp[0])) 
      { 
         num=((int)yp[0]) || 
            rules->language[f_year_number_from_name](yp[0]); 
         if (!num) 
            error("no such year %O in %O\n",yp[0],this); 
      } 
      else if(sizeof(yp)) 
         num=yp[0]; 
 
      if (!sizeof(yp) || (num==-1 && !n)) 
         return Year("ymd_y",rules,v*19-18,yd,1); 
 
      if (num<0) num+=1+number_of_years(); 
      if(0 < num && num < 20) 
        return Year("ymd_yn",rules,v*19-18+num-1,1); 
 
      error("not in range; Year 1..%d exist in %O\n", 
            number_of_years(),this); 
   } 
 
   array(cYear) years(int ...range) 
   { 
      int from=1,n=number_of_years(),to=n; 
 
      if (sizeof(range)) 
         if (sizeof(range)<2) 
            error("Illegal numbers of arguments to years()\n"); 
         else 
         { 
            [from,to]=range; 
            if (from>n) return ({}); else if (from<1) from=1; 
            if (to>n) to=n; else if (to<from) return ({}); 
         } 
 
      return map(enumerate(1+to-from,1,from+m-1), 
                 lambda(int x) 
                 { return Year("ymd_yn",rules,v*19-18+x-1,1); }); 
   } 
 
   int number_of_years() 
   { 
     return 19*n; 
   } 
 
   int number_of_days() 
   { 
     return (this+1)->julian_day()-julian_day(); 
   } 
 
   TimeRange _move(int m,YMD step) 
   { 
      if (!step->n || !m) 
         return this; 
 
      if (step->is_vahid) 
         return Vahid("ymd_v",rules,v+m*step->n,n) 
            ->autopromote(); 
 
      if (step->is_year) 
         return year()->add(m,step)->set_size(this); 
/* 
      if (step->is_month) 
         return month()->add(m,step)->set_size(this); 
 
//        if (step->is_week) 
//       return week()->add(m,step)->set_size(this); 
*/ 
      if (step->is_ymd) 
         return Day("ymd_jd",rules, 
                    vjd+m*step->number_of_days(),number_of_days()) 
            ->autopromote(); 
 
      error("_move: Incompatible type %O\n",step); 
   } 
 
   YMD autopromote() { return this; } 
}