when_exe 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +333 -212
- data/bin/make_ttl.rb +37 -0
- data/bin/make_ttl.rb.config +9 -0
- data/lib/when_exe.rb +923 -925
- data/lib/when_exe/calendarnote.rb +9 -5
- data/lib/when_exe/coordinates.rb +2437 -2446
- data/lib/when_exe/inspect.rb +1480 -1408
- data/lib/when_exe/linkeddata.rb +574 -0
- data/lib/when_exe/locales/akt.rb +177 -176
- data/lib/when_exe/locales/locale.rb +751 -751
- data/lib/when_exe/mini_application.rb +307 -307
- data/lib/when_exe/parts/resource.rb +1115 -1103
- data/lib/when_exe/region/chinese/epochs.rb +6 -5
- data/lib/when_exe/region/christian.rb +831 -829
- data/lib/when_exe/region/japanese.rb +93 -93
- data/lib/when_exe/region/japanese/notes.rb +1510 -1495
- data/lib/when_exe/region/japanese/residues.rb +13 -13
- data/lib/when_exe/tmposition.rb +2307 -2273
- data/lib/when_exe/tmreference.rb +1744 -1734
- data/lib/when_exe/version.rb +2 -2
- data/link_to_online_documents +1 -1
- data/test/scripts/3.ext.rb +6 -6
- data/test/scripts/3.rb +6 -6
- data/test/test.rb +76 -75
- data/test/test/icalendar.rb +883 -879
- data/test/test/linkeddata.rb +224 -0
- data/test/test/region/m17n.rb +193 -193
- data/when_exe.gemspec +3 -2
- metadata +13 -6
data/lib/when_exe/inspect.rb
CHANGED
@@ -1,1408 +1,1480 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
=begin
|
3
|
-
Copyright (C) 2011-
|
4
|
-
|
5
|
-
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
|
-
=end
|
7
|
-
|
8
|
-
module When
|
9
|
-
module Parts::Resource
|
10
|
-
|
11
|
-
# option key for _m17n_form
|
12
|
-
# @private
|
13
|
-
FormOptions = [:precision, :camel, :method, :locale, :prefix]
|
14
|
-
|
15
|
-
# When::Parts::Resource オブジェクトを分かりやすい文字列にして返します
|
16
|
-
#
|
17
|
-
# @return [String] 先頭部分を簡約表現にした IRI
|
18
|
-
#
|
19
|
-
def inspect
|
20
|
-
return super unless @_pool
|
21
|
-
expression = iri(true)
|
22
|
-
expression == '' ? super : When::EncodingConversion.to_external_encoding(expression)
|
23
|
-
end
|
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
|
-
def
|
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
|
-
# @return [
|
162
|
-
#
|
163
|
-
def
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
#
|
170
|
-
#
|
171
|
-
# @return [
|
172
|
-
#
|
173
|
-
def
|
174
|
-
return @remainder.to_s
|
175
|
-
return label
|
176
|
-
@format
|
177
|
-
end
|
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
|
-
# @return [
|
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
|
-
# @return [Array<
|
340
|
-
#
|
341
|
-
def
|
342
|
-
[
|
343
|
-
end
|
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
|
-
dates
|
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
|
-
#
|
657
|
-
#
|
658
|
-
#
|
659
|
-
#
|
660
|
-
#
|
661
|
-
#
|
662
|
-
#
|
663
|
-
#
|
664
|
-
#
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
#
|
692
|
-
|
693
|
-
|
694
|
-
#
|
695
|
-
#
|
696
|
-
# @
|
697
|
-
#
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
#
|
706
|
-
#
|
707
|
-
#
|
708
|
-
#
|
709
|
-
#
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
return
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
#
|
719
|
-
#
|
720
|
-
# @
|
721
|
-
#
|
722
|
-
#
|
723
|
-
#
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
#
|
733
|
-
#
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
#
|
739
|
-
#
|
740
|
-
#
|
741
|
-
#
|
742
|
-
#
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
#
|
783
|
-
#
|
784
|
-
# @
|
785
|
-
#
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
#
|
859
|
-
#
|
860
|
-
#
|
861
|
-
#
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
#
|
883
|
-
#
|
884
|
-
#
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
end
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
#
|
897
|
-
#
|
898
|
-
#
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
#
|
921
|
-
#
|
922
|
-
# @
|
923
|
-
#
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
#
|
935
|
-
#
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
#
|
949
|
-
#
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
#
|
989
|
-
#
|
990
|
-
#
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
end
|
1018
|
-
|
1019
|
-
#
|
1020
|
-
#
|
1021
|
-
#
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
#
|
1030
|
-
#
|
1031
|
-
#
|
1032
|
-
#
|
1033
|
-
#
|
1034
|
-
#
|
1035
|
-
#
|
1036
|
-
#
|
1037
|
-
#
|
1038
|
-
# -
|
1039
|
-
# [
|
1040
|
-
# [
|
1041
|
-
#
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
end
|
1048
|
-
|
1049
|
-
#
|
1050
|
-
#
|
1051
|
-
#
|
1052
|
-
# @
|
1053
|
-
#
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
#
|
1074
|
-
#
|
1075
|
-
# @
|
1076
|
-
#
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
#
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
#
|
1094
|
-
#
|
1095
|
-
# @
|
1096
|
-
#
|
1097
|
-
# @return [
|
1098
|
-
#
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
#
|
1104
|
-
#
|
1105
|
-
#
|
1106
|
-
#
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
#
|
1112
|
-
#
|
1113
|
-
#
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
#
|
1120
|
-
#
|
1121
|
-
# @param [
|
1122
|
-
#
|
1123
|
-
# @return [
|
1124
|
-
#
|
1125
|
-
def
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
#
|
1146
|
-
#
|
1147
|
-
#
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
#
|
1153
|
-
#
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
#
|
1163
|
-
#
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
#
|
1173
|
-
#
|
1174
|
-
# @return [Numeric]
|
1175
|
-
#
|
1176
|
-
def
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
#
|
1189
|
-
#
|
1190
|
-
#
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
#
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
#
|
1215
|
-
#
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
#
|
1228
|
-
#
|
1229
|
-
# @
|
1230
|
-
#
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
#
|
1240
|
-
#
|
1241
|
-
# @param [
|
1242
|
-
#
|
1243
|
-
#
|
1244
|
-
#
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
#
|
1265
|
-
#
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
#
|
1282
|
-
#
|
1283
|
-
# @
|
1284
|
-
#
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
return
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
#
|
1335
|
-
#
|
1336
|
-
#
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
#
|
1355
|
-
#
|
1356
|
-
#
|
1357
|
-
# @
|
1358
|
-
#
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin
|
3
|
+
Copyright (C) 2011-2015 Takashi SUGA
|
4
|
+
|
5
|
+
You may use and/or modify this file according to the license described in the LICENSE.txt file included in this archive.
|
6
|
+
=end
|
7
|
+
|
8
|
+
module When
|
9
|
+
module Parts::Resource
|
10
|
+
|
11
|
+
# option key for _m17n_form
|
12
|
+
# @private
|
13
|
+
FormOptions = [:precision, :camel, :method, :locale, :prefix]
|
14
|
+
|
15
|
+
# When::Parts::Resource オブジェクトを分かりやすい文字列にして返します
|
16
|
+
#
|
17
|
+
# @return [String] 先頭部分を簡約表現にした IRI
|
18
|
+
#
|
19
|
+
def inspect
|
20
|
+
return super unless @_pool
|
21
|
+
expression = iri(true)
|
22
|
+
expression == '' ? super : When::EncodingConversion.to_external_encoding(expression)
|
23
|
+
end
|
24
|
+
|
25
|
+
# 多言語対応文字列化
|
26
|
+
#
|
27
|
+
# @return [When::BasicTypes::M17n]
|
28
|
+
#
|
29
|
+
def to_m17n
|
30
|
+
label
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# オブジェクトの内容を Hash 化
|
35
|
+
#
|
36
|
+
# @param [String, Integer] options {When::TM::TemporalPosition#_to_h}に渡す
|
37
|
+
# @param [Hash] options 下記のとおり
|
38
|
+
# @option options [Numeric] :precision 指定があれば「イベント名(イベント時刻)」出力の時刻を指定の精度に丸める
|
39
|
+
# @option options [Boolean] :camel true ならシンボルを camel case にする
|
40
|
+
# @option options [Symbol] :method _to_hash_value で変換に用いるメソッド(:to_m17n, :iri など, 指定なしなら変換しない)
|
41
|
+
# @option options [String] :locale 文字列化の locale(指定なしは M17nオブジェクトに変換)
|
42
|
+
# @option options [Boolean] :prefix true ならIRI の先頭部分を簡約表現にする
|
43
|
+
# @option options [Object] :その他 各クラス#_to_h を参照
|
44
|
+
#
|
45
|
+
# @return [Hash] (Whenモジュール内のクラスは文字列 or M17n化)
|
46
|
+
#
|
47
|
+
def to_h(options={})
|
48
|
+
_m17n_form(_to_h(options), options.kind_of?(Hash) ? options : {})
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# オブジェクトの内容を JSON 化
|
53
|
+
#
|
54
|
+
# @param [Object] options #to_h を参照
|
55
|
+
#
|
56
|
+
# @return [String] to_h 結果を JSON文字列化したもの
|
57
|
+
#
|
58
|
+
def to_json(options={})
|
59
|
+
options[:method] = :to_m17n unless options.key?(:method)
|
60
|
+
JSON.dump(to_h(options))
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# _m17n_form のための要素生成
|
65
|
+
# @private
|
66
|
+
def _to_hash_value(options={})
|
67
|
+
method = options[:method]
|
68
|
+
if method.kind_of?(Symbol)
|
69
|
+
if respond_to?(method, true) && method != :iri
|
70
|
+
return send(method)
|
71
|
+
elsif registered?
|
72
|
+
return iri(options[:prefix])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
#
|
80
|
+
# 時間位置オブジェクトの内容を Hash 化
|
81
|
+
#
|
82
|
+
# @param [Object] options #to_h を参照
|
83
|
+
#
|
84
|
+
# @return [Hash]
|
85
|
+
# 各クラスの HashProperty に列挙した属性のうち値が false/nil でないものを
|
86
|
+
# 属性 => 値
|
87
|
+
# とする Hash
|
88
|
+
#
|
89
|
+
def _to_h(options={})
|
90
|
+
hash = {}
|
91
|
+
self.class::HashProperty.each do |property|
|
92
|
+
method, skip = property
|
93
|
+
value = respond_to?(method, true) ? send(method) : skip
|
94
|
+
hash[method] = value unless value == skip || value.class == skip
|
95
|
+
end
|
96
|
+
hash
|
97
|
+
rescue
|
98
|
+
{}
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# element を 文字列(M17n), Numeric あるいはそれらの Hash や Array に変換したもの
|
103
|
+
#
|
104
|
+
# @param [Object] element 変換元
|
105
|
+
# @param [Hash] options 下記の通り
|
106
|
+
# @option options [Numeric] :precision 指定があれば「イベント名(イベント時刻)」出力の時刻を指定の精度に丸める
|
107
|
+
# @option options [Boolean] :camel true ならシンボルを camel case にする
|
108
|
+
# @option options [Symbol] :method _to_hash_value で変換に用いるメソッド(:to_m17n, :iri など, 指定なしなら変換しない)
|
109
|
+
# @option options [String] :locale 文字列化の locale(指定なしは M17nオブジェクトに変換)
|
110
|
+
# @option options [Boolean] :prefix true ならIRI の先頭部分を簡約表現にする
|
111
|
+
#
|
112
|
+
# @return [Hash, Array] 変換結果
|
113
|
+
#
|
114
|
+
# @note element.events のある日付は _event_form で変換する
|
115
|
+
#
|
116
|
+
def _m17n_form(element, options={})
|
117
|
+
result = element.respond_to?(:_event_form) ? element._event_form(self, options) :
|
118
|
+
element.respond_to?(:_to_hash_value) ? element._to_hash_value(options) :
|
119
|
+
element.respond_to?(:label) && element.label ? element.label :
|
120
|
+
case element
|
121
|
+
when Hash ; Hash[*(element.keys.inject([]) { |s, k|
|
122
|
+
s + [_m17n_form(k, options), _m17n_form(element[k], options)]
|
123
|
+
})]
|
124
|
+
when Array ; element.map {|e| _m17n_form(e, options)}
|
125
|
+
when Class ; When::Parts::Resource._path_with_prefix(element, options[:prefix])
|
126
|
+
when Symbol ; options[:camel] ? element.to_s.split(/_/).map {|e| e.capitalize}.join('').to_sym : element
|
127
|
+
when Numeric, FalseClass, TrueClass ; element
|
128
|
+
else ; element.to_s
|
129
|
+
end
|
130
|
+
result = When::Locale.translate(result,options[:locale]) if options[:locale] && result.kind_of?(String)
|
131
|
+
result
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
class Parts::Timezone
|
136
|
+
# When::Parts::Timezone オブジェクトを分かりやすい文字列にして返します
|
137
|
+
#
|
138
|
+
# @return [String] identifier と同様
|
139
|
+
#
|
140
|
+
alias :inspect :identifier
|
141
|
+
end
|
142
|
+
|
143
|
+
module Coordinates
|
144
|
+
|
145
|
+
class Pair
|
146
|
+
#
|
147
|
+
# to_h のための要素生成
|
148
|
+
#
|
149
|
+
# @param [Hash] options 下記のとおり
|
150
|
+
# @option options [Symbol] :method :to_m17n なら to_s を返す、その他は self を返す
|
151
|
+
#
|
152
|
+
# @return [String, When::Coordinates::Pair]
|
153
|
+
#
|
154
|
+
# @private
|
155
|
+
def _to_hash_value(options={})
|
156
|
+
options[:method] == :to_m17n ? to_s : self
|
157
|
+
end
|
158
|
+
|
159
|
+
# When::Coordinates::Pair オブジェクトを分かりやすい文字列にして返します
|
160
|
+
#
|
161
|
+
# @return [String] to_s と同様
|
162
|
+
#
|
163
|
+
def inspect
|
164
|
+
When::EncodingConversion.to_external_encoding(to_s)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
class Residue
|
169
|
+
# 多言語対応文字列化
|
170
|
+
#
|
171
|
+
# @return [When::BasicTypes::M17n]
|
172
|
+
#
|
173
|
+
def to_m17n
|
174
|
+
return m17n(@remainder.to_s) unless label
|
175
|
+
return label + "(#{difference})" unless @format
|
176
|
+
(label[0...0] + @format) % [label, difference, difference+1]
|
177
|
+
end
|
178
|
+
|
179
|
+
# 文字列化
|
180
|
+
#
|
181
|
+
# @return [String]
|
182
|
+
#
|
183
|
+
def to_s
|
184
|
+
return @remainder.to_s unless label
|
185
|
+
return label.to_s + "(#{difference})" unless @format
|
186
|
+
@format.to_s % [label.to_s, difference, difference+1]
|
187
|
+
end
|
188
|
+
|
189
|
+
#
|
190
|
+
# week_included のための range の決定
|
191
|
+
#
|
192
|
+
# @return [Array<Range>]
|
193
|
+
#
|
194
|
+
# @private
|
195
|
+
def _range_for_week_included(date, first, length, block_given=false)
|
196
|
+
today = date.floor
|
197
|
+
begun = today.succ & self >> first-1
|
198
|
+
unless date.frame.equal?(begun.frame)
|
199
|
+
begun = (date.frame ^ today).succ & self >> first-1
|
200
|
+
middle = today
|
201
|
+
end
|
202
|
+
ended = begun.succ & self >> length-1
|
203
|
+
middle && block_given ? [begun...middle, middle...ended] : [begun...ended]
|
204
|
+
end
|
205
|
+
|
206
|
+
#
|
207
|
+
# week_included のためのコラムの生成
|
208
|
+
#
|
209
|
+
# @return [Array<Object>]
|
210
|
+
#
|
211
|
+
# @private
|
212
|
+
def _column_for_week_included(base, range, opt, &block)
|
213
|
+
range.inject([]) {|s,r| s + r.map { |date|
|
214
|
+
yield(date, !opt.key?(:Range) || opt[:Range].include?(date.to_i) ? DAY : nil)
|
215
|
+
}}
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
class CalendarNote::Week
|
221
|
+
|
222
|
+
#
|
223
|
+
# week_included のための range の決定
|
224
|
+
#
|
225
|
+
# @return [Array<Range>]
|
226
|
+
#
|
227
|
+
# @private
|
228
|
+
def _range_for_week_included(date, first, length, block_given=false)
|
229
|
+
begun = ended = nil
|
230
|
+
if first <= 0
|
231
|
+
it = enum_for(date.floor, :reverse)
|
232
|
+
(1-first).times do
|
233
|
+
begun = it.next
|
234
|
+
end
|
235
|
+
else
|
236
|
+
it = enum_for(date.floor, :forward)
|
237
|
+
first.times do
|
238
|
+
begun = it.next
|
239
|
+
end
|
240
|
+
end
|
241
|
+
it = enum_for(begun, :forward)
|
242
|
+
(length+1).times do
|
243
|
+
ended = it.next
|
244
|
+
end
|
245
|
+
[begun...ended]
|
246
|
+
end
|
247
|
+
|
248
|
+
#
|
249
|
+
# week_included のためのコラムの生成
|
250
|
+
#
|
251
|
+
# @return [Array<Object>]
|
252
|
+
#
|
253
|
+
# @private
|
254
|
+
def _column_for_week_included(base, range, opt, &block)
|
255
|
+
count = 0
|
256
|
+
limit = week(base)[:position][1]
|
257
|
+
range.inject([]) {|s,r| s + r.map { |date|
|
258
|
+
position = week(date, base)[:position][0]
|
259
|
+
(position - count).times do
|
260
|
+
yield(nil,nil)
|
261
|
+
end
|
262
|
+
count = position + 1
|
263
|
+
yield(date, !opt.key?(:Range) || opt[:Range].include?(date.to_i) ? DAY : nil) if position < limit
|
264
|
+
}}
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
module TM
|
269
|
+
|
270
|
+
class Calendar
|
271
|
+
|
272
|
+
# TemporalPosition#strftime のためのデフォルト書式
|
273
|
+
#
|
274
|
+
# @return [String]
|
275
|
+
#
|
276
|
+
def strftime
|
277
|
+
@strftime ||= '%Y-%m-%d'
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
class TemporalPosition
|
282
|
+
|
283
|
+
AMPM = ['AM', 'PM'].map {|half| When::Parts::Resource._instance('_m:CalendarFormats::' + half)}
|
284
|
+
Format = {
|
285
|
+
'a' => ['%s', 'a'], 'A' => ['%s', 'A'], 'b' => ['%s', 'b'], 'B' => ['%s', 'B'],
|
286
|
+
'c' => When::Parts::Resource._instance('_m:CalendarFormats::DateTime'),
|
287
|
+
'C' => ['%02d', 'C'], 'd' => ['%02d', 'd'], 'D' => '%m/%d/%y', 'e' => ['%2d', 'd'],
|
288
|
+
'E' => ['%s', 'E'], 'F' => ['%s', 'F'], 'G' => ['%d', 'G'], 'g' => ['%02d', 'g'],
|
289
|
+
'h' => '%b', 'H' => ['%02d', 'H'], 'I' => ['%02d', 'I'], 'j' => ['%03d', 'j'],
|
290
|
+
'k' => ['%2d', 'H'], 'l' => ['%2d', 'I'], 'm' => ['%02d', 'm'], 'M' => ['%02d', 'M'],
|
291
|
+
'n' => '\n', 'p' => ['%s', 'p'], 'P' => ['%s', 'P'], 'q' => ['%01d', 'd'],
|
292
|
+
'r' => '%I:%M:%S %p', 'R' => '%H:%M', 's' => ['%d', 's'], 'S' => ['%02d', 'S'],
|
293
|
+
't' => '\t', 'T' => '%H:%M:%S', 'u' => ['%d', 'u'], 'U' => ['%02d', 'U'],
|
294
|
+
'V' => ['%02d', 'V'], 'w' => ['%d', 'w'], 'W' => ['%02d', 'W'],
|
295
|
+
'x' => When::Parts::Resource._instance('_m:CalendarFormats::Date'),
|
296
|
+
'X' => When::Parts::Resource._instance('_m:CalendarFormats::Time'),
|
297
|
+
'y' => ['%02d', 'y'], 'Y' => ['%4d', 'Y'], 'z' => ['%s', 'z'], 'Z' => ['%s', 'Z'],
|
298
|
+
'+' => '%a %b %d %T %z %Y'
|
299
|
+
}
|
300
|
+
|
301
|
+
class << self
|
302
|
+
# When::TM::TemporalPosition Class のグローバルな設定を行う
|
303
|
+
#
|
304
|
+
# @param [Hash] format strftime で用いる記号の定義
|
305
|
+
#
|
306
|
+
# @return [void]
|
307
|
+
#
|
308
|
+
# @note format の指定がない場合、format は Format(モジュール定数)と解釈する
|
309
|
+
#
|
310
|
+
def _setup_(format=nil)
|
311
|
+
@format = format ? Format.merge(format) : Format
|
312
|
+
end
|
313
|
+
|
314
|
+
# 設定情報を取得する
|
315
|
+
#
|
316
|
+
# @return [Hash] 設定情報
|
317
|
+
#
|
318
|
+
def _setup_info
|
319
|
+
{:format => format}
|
320
|
+
end
|
321
|
+
|
322
|
+
# strftime で用いる書式のハッシュ
|
323
|
+
def format
|
324
|
+
@format ||= Format
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
# When::TM::TemporalPosition オブジェクトを分かりやすい文字列にして返します
|
329
|
+
#
|
330
|
+
# @return [String] to_s と同様
|
331
|
+
#
|
332
|
+
def inspect
|
333
|
+
When::EncodingConversion.to_external_encoding(to_s)
|
334
|
+
end
|
335
|
+
|
336
|
+
#
|
337
|
+
# 暦法名
|
338
|
+
#
|
339
|
+
# @return [Array<Class>] Class 暦法のクラスオブジェクト
|
340
|
+
#
|
341
|
+
def calendar_name
|
342
|
+
[self.class]
|
343
|
+
end
|
344
|
+
|
345
|
+
#
|
346
|
+
# 時法名
|
347
|
+
# @param [Boolean] prefix true ならIRI の先頭部分を簡約表現にする
|
348
|
+
#
|
349
|
+
# @return [Array<String>] String 時法の IRI
|
350
|
+
#
|
351
|
+
def clock_name(prefix=true)
|
352
|
+
[clock.iri(prefix)]
|
353
|
+
end
|
354
|
+
|
355
|
+
#
|
356
|
+
# 参照ラベル
|
357
|
+
#
|
358
|
+
# @return [When::BasicTypes::M17n]
|
359
|
+
#
|
360
|
+
def reference_label
|
361
|
+
[When::BasicTypes::M17n.new(self.class.to_s.split(/::/)[-1])]
|
362
|
+
end
|
363
|
+
|
364
|
+
# 含まれる週
|
365
|
+
#
|
366
|
+
# @overload week_included(ord, wkst, opt, &block)
|
367
|
+
# @param [Numeric, Range] ord 週の番号(default: 今週)
|
368
|
+
# 今週を 0 とする週番号(Integer) または週番号の範囲(Range)
|
369
|
+
# -1 - 先週
|
370
|
+
# 0 - 今週
|
371
|
+
# +1 - 来週
|
372
|
+
# @param [String] wkst 週の開始曜日(defaultは 月曜)
|
373
|
+
# @param [When::CalendarNote] wkst 暦注オブジェクト
|
374
|
+
# @param [Array<When::CalendarNote, String>] wkst 暦注オブジェクトとそのイベントメソッド名
|
375
|
+
# (暦注オブジェクトは、そのIRI文字列を指定しても良い)
|
376
|
+
# @param [Hash] opt 下記の通り
|
377
|
+
# @option opt [Range] :Range 上位繰り返し範囲(ユリウス通日...ユリウス通日)
|
378
|
+
# @param [Block] block
|
379
|
+
#
|
380
|
+
# @note 引数 ord, wkst, opt はそのクラスで位置づけを判断するため、引数の順序は任意(省略も可)
|
381
|
+
#
|
382
|
+
# @return [Range] 含まれる週を範囲として表現する Range (block 指定なし)
|
383
|
+
# @return [Array] 含まれる週の各日をブロックに渡した結果の Array (block 指定あり)
|
384
|
+
#
|
385
|
+
def week_included(*args, &block)
|
386
|
+
begin
|
387
|
+
first, length, wkst, opt = _range(args, 'MO')
|
388
|
+
range = wkst._range_for_week_included(self, first, length, block_given?)
|
389
|
+
rescue RangeError
|
390
|
+
range = wkst._range_for_week_included(@frame ^ self, first, length)
|
391
|
+
end
|
392
|
+
|
393
|
+
return range.first unless block_given?
|
394
|
+
|
395
|
+
wkst._column_for_week_included(self, range, opt, &block).unshift(yield(range[0].first, WEEK)).compact
|
396
|
+
end
|
397
|
+
|
398
|
+
# 含まれる月
|
399
|
+
#
|
400
|
+
# @overload month_included(ord, wkst, opt, block)
|
401
|
+
# @param [Numeric, Range] ord 月の番号(default: 今月)
|
402
|
+
# 今月を 0 とする月番号(Integer) または月番号の範囲(Range)
|
403
|
+
# -1 - 先月
|
404
|
+
# 0 - 今月
|
405
|
+
# +1 - 来月
|
406
|
+
# @param [String] wkst 週の開始曜日(defaultはなし)
|
407
|
+
# @param [When::CalendarNote] wkst 暦注オブジェクト
|
408
|
+
# @param [Array<When::CalendarNote, String>] wkst 暦注オブジェクトとそのイベントメソッド名
|
409
|
+
# (暦注オブジェクトは、そのIRI文字列を指定しても良い)
|
410
|
+
# @param [Hash] opt 下記の通り
|
411
|
+
# @option opt [Range] :Range 上位繰り返し範囲(ユリウス通日...ユリウス通日)
|
412
|
+
# @param [Block] block
|
413
|
+
#
|
414
|
+
# @note 引数 ord, wkst, opt はそのクラスで位置づけを判断するため、引数の順序は任意(省略も可)
|
415
|
+
#
|
416
|
+
# @return [Range] 含まれる月を範囲として表現する Range (block 指定なし)
|
417
|
+
# @return [Array] 含まれる月の各日をブロックに渡した結果の Array (block 指定あり, wkst なし)
|
418
|
+
# @return [Array<Array>] 含まれる月の各日をブロックに渡した結果の 七曜表(block 指定あり, wkst あり)
|
419
|
+
#
|
420
|
+
def month_included(*args, &block)
|
421
|
+
first, length, wkst, opt = _range(args)
|
422
|
+
if wkst
|
423
|
+
(first...(first+length)).map {|i|
|
424
|
+
begun = self.floor(MONTH,DAY) + When::TM::PeriodDuration.new([0,i,0])
|
425
|
+
ended = begun + P1M
|
426
|
+
ended = ended.prev until begun.cal_date[MONTH-1] == ended.cal_date[MONTH-1]
|
427
|
+
if ended.to_i <= begun.to_i
|
428
|
+
ended = begun
|
429
|
+
loop do
|
430
|
+
succ = ended.succ
|
431
|
+
break unless succ.frame.equal?(begun.frame)
|
432
|
+
ended = succ
|
433
|
+
end
|
434
|
+
end
|
435
|
+
dates = [begun]
|
436
|
+
loop do
|
437
|
+
current = dates[-1].week_included(wkst)
|
438
|
+
if current.last.to_i > ended.to_i
|
439
|
+
dates[-1] = ended
|
440
|
+
break (dates.map {|date| date.week_included(wkst, {:Range=>begun.to_i..ended.to_i}, &block)}).
|
441
|
+
unshift(yield(begun, MONTH)).compact
|
442
|
+
elsif wkst.kind_of?(When::Coordinates::Residue)
|
443
|
+
dates << dates[-1] + wkst.duration
|
444
|
+
else
|
445
|
+
it = wkst.enum_for(dates[-1], :forward)
|
446
|
+
begin
|
447
|
+
date = it.next
|
448
|
+
end while date.to_i == dates[-1].to_i
|
449
|
+
date = date.to_cal_date unless date.instance_of?(TM::CalDate)
|
450
|
+
dates << date
|
451
|
+
end
|
452
|
+
end
|
453
|
+
}
|
454
|
+
else
|
455
|
+
begun = self.floor(MONTH,DAY) + When::TM::PeriodDuration.new([0, first, 0])
|
456
|
+
ended = begun + When::TM::PeriodDuration.new([0, length, 0])
|
457
|
+
loop do
|
458
|
+
last = ended.prev
|
459
|
+
break unless last.cal_date[MONTH-1] == ended.cal_date[MONTH-1]
|
460
|
+
ended = last
|
461
|
+
end
|
462
|
+
if block_given?
|
463
|
+
(begun...ended).map do |date|
|
464
|
+
yield(date)
|
465
|
+
end
|
466
|
+
else
|
467
|
+
begun...ended
|
468
|
+
end
|
469
|
+
end
|
470
|
+
end
|
471
|
+
|
472
|
+
# 含まれる年
|
473
|
+
#
|
474
|
+
# @overload month_included(ord, wkst, opt, block)
|
475
|
+
# @param [Numeric, Range] ord 年の番号(default: 今年)
|
476
|
+
# 今年を 0 とする年番号(Integer) または年番号の範囲(Range)
|
477
|
+
# -1 - 先年
|
478
|
+
# 0 - 今年
|
479
|
+
# +1 - 来年
|
480
|
+
# @param [String] wkst 週の開始曜日(defaultはなし)
|
481
|
+
# @param [When::CalendarNote] wkst 暦注オブジェクト
|
482
|
+
# @param [Array<When::CalendarNote, String>] wkst 暦注オブジェクトとそのイベントメソッド名
|
483
|
+
# (暦注オブジェクトは、そのIRI文字列を指定しても良い)
|
484
|
+
# @param [Hash] opt 下記の通り
|
485
|
+
# @option opt [Range] :Range 上位繰り返し範囲(ユリウス通日...ユリウス通日)
|
486
|
+
# @param [Block] block
|
487
|
+
#
|
488
|
+
# @note 引数 ord, wkst, opt はそのクラスで位置づけを判断するため、引数の順序は任意(省略も可)
|
489
|
+
#
|
490
|
+
# @return [Range] 含まれる年を範囲として表現する Range (block 指定なし)
|
491
|
+
# @return [Array] 含まれる年の各日をブロックに渡した結果の Array (block 指定あり, wkst なし)
|
492
|
+
# @return [Array<Array>] 含まれる年の各日をブロックに渡した結果の 七曜表(block 指定あり, wkst あり)
|
493
|
+
#
|
494
|
+
def year_included(*args, &block)
|
495
|
+
first, length, wkst, opt = _range(args)
|
496
|
+
if wkst
|
497
|
+
(first...(first+length)).map {|i|
|
498
|
+
begun = _force_euqal_year(i)
|
499
|
+
ended = _force_euqal_year(i+1)
|
500
|
+
current = begun
|
501
|
+
result = [yield(begun, YEAR)]
|
502
|
+
ended += P1M if ended.floor(MONTH).most_significant_coordinate * 1 == begun.most_significant_coordinate * 1
|
503
|
+
while current < ended do
|
504
|
+
result << current.month_included(wkst, &block)
|
505
|
+
current += P1M
|
506
|
+
end
|
507
|
+
result.compact
|
508
|
+
}
|
509
|
+
else
|
510
|
+
begun = _force_euqal_year(first)
|
511
|
+
ended = _force_euqal_year(first+length)
|
512
|
+
if block_given?
|
513
|
+
(begun...ended).map do |date|
|
514
|
+
yield(date)
|
515
|
+
end
|
516
|
+
else
|
517
|
+
begun...ended
|
518
|
+
end
|
519
|
+
end
|
520
|
+
end
|
521
|
+
|
522
|
+
# 指定の年初を探す
|
523
|
+
def _force_euqal_year(diff)
|
524
|
+
year = most_significant_coordinate * 1 + diff
|
525
|
+
date = (self + When::TM::PeriodDuration.new([diff,0,0])).floor(YEAR,DAY)
|
526
|
+
done = {}
|
527
|
+
loop do
|
528
|
+
case
|
529
|
+
when date.most_significant_coordinate * 1 == year
|
530
|
+
return date
|
531
|
+
when date.most_significant_coordinate * 1 > year
|
532
|
+
next_date = (date-When::P1Y).floor(YEAR,DAY)
|
533
|
+
date = (date.to_i == next_date.to_i) ?
|
534
|
+
(date-When::P1Y*2).floor(YEAR,DAY) :
|
535
|
+
next_date
|
536
|
+
else
|
537
|
+
next_date = (date+When::P1Y).floor(YEAR,DAY)
|
538
|
+
date = (date.to_i == next_date.to_i) ?
|
539
|
+
(date+When::P1Y*2).floor(YEAR,DAY) :
|
540
|
+
next_date
|
541
|
+
end
|
542
|
+
raise RangeError, "can't find target date: #{self} -> #{year}" if done.key?(date.to_i)
|
543
|
+
done[date.to_i] = true
|
544
|
+
end
|
545
|
+
end
|
546
|
+
private :_force_euqal_year
|
547
|
+
|
548
|
+
# 範囲の取得
|
549
|
+
def _range(args, wkst=nil)
|
550
|
+
ord = 0
|
551
|
+
opt = {}
|
552
|
+
args.each do |arg|
|
553
|
+
case arg
|
554
|
+
when Integer, Range ; ord = arg
|
555
|
+
when Hash ; opt = arg
|
556
|
+
else ; wkst = arg
|
557
|
+
end
|
558
|
+
end
|
559
|
+
wkst, method = wkst
|
560
|
+
wkst = When::Coordinates::Residue.day_of_week(wkst) || When.CalendarNote(wkst) if wkst
|
561
|
+
wkst = wkst[method] if method
|
562
|
+
return ord, 1, wkst, opt if ord.kind_of?(Integer)
|
563
|
+
length = ord.last - ord.first
|
564
|
+
length += 1 unless ord.exclude_end?
|
565
|
+
return ord.first, length, wkst, opt
|
566
|
+
end
|
567
|
+
private :_range
|
568
|
+
|
569
|
+
#
|
570
|
+
# 時間位置オブジェクトの暦注を取得し value を暦注の値 (String, When::BasicTypes::M17n or When::Coordinates::Residue)とする Hash で表現
|
571
|
+
#
|
572
|
+
# @param [String] options { :notes => String } という Hash の指定と等価
|
573
|
+
# @param [Integer] options { :indices => Integer } という Hash の指定と等価
|
574
|
+
# @param [Hash] options 下記のとおり
|
575
|
+
# @option options [When::CalendarNote, String] :calendar_note 暦注を計算する暦注オブジェクトまたはそのIRI
|
576
|
+
# @option options [Object] その他のキー {When::CalendarNote#notes} を参照
|
577
|
+
#
|
578
|
+
# @return [Array<Array<Hash{:note=>note, :value=>value}>>]
|
579
|
+
# [ note [String, When::BasicTypes::M17n] 暦注名 ]
|
580
|
+
# [ value [String, When::BasicTypes::M17n, When::Coordinates::Residue] 暦注の値 ]
|
581
|
+
#
|
582
|
+
def notes(options={})
|
583
|
+
form_options = options.kind_of?(Hash) ? options : {}
|
584
|
+
form_options[:method] = :to_m17n unless form_options.key?(:method)
|
585
|
+
persistence = options.delete(:persistence) if options.kind_of?(Hash)
|
586
|
+
retrieved = When::CalendarNote::NotesContainer.retrieve(persistence, self.to_i)
|
587
|
+
return retrieved unless retrieved == false
|
588
|
+
When::CalendarNote::NotesContainer.register(_m17n_form(_notes(options), form_options), persistence, self.to_i)
|
589
|
+
end
|
590
|
+
|
591
|
+
#
|
592
|
+
# 時間位置オブジェクトの暦注を取得
|
593
|
+
#
|
594
|
+
# @param [String] options { :notes => String } という Hash の指定と等価
|
595
|
+
# @param [Integer] options { :indices => Integer } という Hash の指定と等価
|
596
|
+
# @param [Hash] options 下記のとおり
|
597
|
+
# @option options [When::CalendarNote, String] :calendar_note 暦注を計算する暦注オブジェクトまたはそのIRI
|
598
|
+
# @option options [Object] その他のキー {When::CalendarNote#notes} を参照
|
599
|
+
#
|
600
|
+
# @return [Array<Array<Hash{:note=>note, :value=>value}>>]
|
601
|
+
# [ note [String, When::BasicTypes::M17n, When::Coordinates::Residue] 暦注名 ]
|
602
|
+
# [ value [String, When::BasicTypes::M17n, When::Coordinates::Residue, When::TM::TemporalPosition] 暦注の値 ]
|
603
|
+
#
|
604
|
+
# @note
|
605
|
+
# When::TM::TemporalPosition の場合、events[0] に暦注名の入ったその暦注に該当する日付である。
|
606
|
+
# (例) Christian クラス で easter を計算した場合、当該年の復活祭の日付オブジェクトが返る。
|
607
|
+
# 暦注サブクラスの場合、要素が増えたり、:note の暦注要素の型が変わったりすることがある。
|
608
|
+
#
|
609
|
+
def _notes(options={})
|
610
|
+
_calendar_note(options).notes(self, options)
|
611
|
+
end
|
612
|
+
|
613
|
+
#
|
614
|
+
# 暦注の一致 or 不一致
|
615
|
+
#
|
616
|
+
# @param [String] options { :notes => String } または { :value => String } という Hash の指定と等価
|
617
|
+
# (指定の notes が存在する場合は前者、しない場合は後者)
|
618
|
+
# @param [Integer] options { :indices => Integer } という Hash の指定と等価
|
619
|
+
# @param [Hash] options 下記のとおり
|
620
|
+
# @option options [Object] :value 確認する暦注の値
|
621
|
+
# @option options [Object] その他のキー {When::CalendarNote#notes} を参照
|
622
|
+
#
|
623
|
+
# @return [Boolean]
|
624
|
+
# [ true - 暦注が一致 ]
|
625
|
+
# [ false - 暦注が不一致 ]
|
626
|
+
#
|
627
|
+
def note?(options={})
|
628
|
+
_calendar_note(options).note?(self, options)
|
629
|
+
end
|
630
|
+
|
631
|
+
# 指定の日時が指定イベントに該当するか?
|
632
|
+
#
|
633
|
+
# @overload is?(event=nil, options={})
|
634
|
+
# @param [String] event options={:notes=>String} または {:notes=>String} または {:value=>String} という指定と等価
|
635
|
+
# (指定の event が存在する場合は前者、指定の notes が存在する場合は中央、しない場合は後者)
|
636
|
+
# @param [Integer] event options={ :indices=> Integer } という指定と等価
|
637
|
+
# @param [Hash] options 下記のとおり
|
638
|
+
# @option options [When::CalendarNote or String] :calendar_note 該当判断に用いる CalendarNoteオブジェクトまたはその IRI
|
639
|
+
# @option options [String] :event 確認するイベント名
|
640
|
+
# @option options [Object] :value 確認する暦注の値
|
641
|
+
# @option options [Object] その他のキー {When::CalendarNote#notes} を参照
|
642
|
+
#
|
643
|
+
# @return [Boolean]
|
644
|
+
# [ true - 該当する ]
|
645
|
+
# [ false - 該当しない ]
|
646
|
+
#
|
647
|
+
def is?(*args)
|
648
|
+
options = args.last.kind_of?(Hash) ? args.pop.dup : {}
|
649
|
+
note = _calendar_note(options)
|
650
|
+
event = args.first || options.delete(:event) || note.event
|
651
|
+
return note.note?(self, options) unless options.empty?
|
652
|
+
return note.note?(self, event) unless event.to_s =~ /\A([^\d]+)/ && note.respond_to?($1.downcase)
|
653
|
+
return note.include?(self, event)
|
654
|
+
end
|
655
|
+
|
656
|
+
#
|
657
|
+
# 時間位置オブジェクトの内容を Hash 化
|
658
|
+
#
|
659
|
+
# @param [String] options { :notes => String } という Hash の指定と等価
|
660
|
+
# @param [Integer] options { :indices => Integer } という Hash の指定と等価
|
661
|
+
# @param [Hash] options 下記のとおり
|
662
|
+
# @option options [When::CalendarNote, String] :calendar_note 暦注を計算する暦注オブジェクトまたはそのIRI
|
663
|
+
# @option options [Object] その他のキー {When::CalendarNote#notes} を参照
|
664
|
+
#
|
665
|
+
# @return [Hash]
|
666
|
+
# - :sdn 日の通し番号 - ユリウス通日(Integer)
|
667
|
+
# - :calendar calendar_name の結果 - Array<暦法または暦年代(, 付属情報..)>
|
668
|
+
# - :notes Hash (の Array (の Array)) - _notes(options)
|
669
|
+
# clock が定義されている場合、さらに下記も出力する
|
670
|
+
# - :clock 時計(When::Parts::Timezone::Base)
|
671
|
+
# - :clk_time to_clock_time の結果 - ( 日, 時, 分, 秒 )
|
672
|
+
# - :dynamical dynamical_time / 秒
|
673
|
+
# - :universal universal_time / 秒
|
674
|
+
#
|
675
|
+
def _to_h(options={})
|
676
|
+
hash = super.update({
|
677
|
+
:sdn => to_i,
|
678
|
+
:calendar => calendar_name,
|
679
|
+
:notes => _notes(options)
|
680
|
+
})
|
681
|
+
|
682
|
+
hash.update({
|
683
|
+
:clock => clock,
|
684
|
+
:clk_time => to_clock_time,
|
685
|
+
:dynamical => dynamical_time * clock.second,
|
686
|
+
:universal => universal_time * clock.second
|
687
|
+
}) if clock
|
688
|
+
hash
|
689
|
+
end
|
690
|
+
|
691
|
+
# 指定の書式による多言語対応文字列化 - pattern で指定した書式で多言語対応文字列化する
|
692
|
+
#
|
693
|
+
# @param [When::BasicTypes::M17n] pattern 書式
|
694
|
+
# @param [String, Array<String>] locale 文字列化を行う locale の指定(デフォルト : オブジェクト生成時に保持している locale すべて)
|
695
|
+
#
|
696
|
+
# @return [When::BasicTypes::M17n]
|
697
|
+
#
|
698
|
+
def strftime(pattern=@frame.strftime, locale=nil)
|
699
|
+
pattern = m17n([pattern]*self.keys.length, nil, nil, {:locale=>self.keys}) if pattern.instance_of?(String)
|
700
|
+
pattern._printf([], locale) do |k, *t|
|
701
|
+
_strftime(k, pattern, [''])
|
702
|
+
end
|
703
|
+
end
|
704
|
+
|
705
|
+
# 多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する
|
706
|
+
#
|
707
|
+
# @overload to_m17n()
|
708
|
+
#
|
709
|
+
# @return [When::BasicTypes::M17n]
|
710
|
+
#
|
711
|
+
def to_m17n(*args)
|
712
|
+
return m17n(I[@indeterminated_position]) if [Unknown, Max, Min].include?(@indeterminated_position)
|
713
|
+
return m17n(_to_s)
|
714
|
+
end
|
715
|
+
# @private
|
716
|
+
alias :_to_s :to_s
|
717
|
+
|
718
|
+
# 文字列化 - When.exe Standard Representation により文字列化する
|
719
|
+
#
|
720
|
+
# @overload to_s()
|
721
|
+
#
|
722
|
+
# @return [String]
|
723
|
+
#
|
724
|
+
def to_s(*args)
|
725
|
+
to_m17n(*args).to_s
|
726
|
+
end
|
727
|
+
|
728
|
+
# URI要素化 - URI表現の要素として用いる形式に変換
|
729
|
+
#
|
730
|
+
# @overload to_uri()
|
731
|
+
#
|
732
|
+
# @return [String]
|
733
|
+
#
|
734
|
+
def to_uri(*args)
|
735
|
+
_to_uri(to_s(*args))
|
736
|
+
end
|
737
|
+
|
738
|
+
# URI要素化 - URI表現の要素として用いる形式に変換(“^”はエスケープ)
|
739
|
+
#
|
740
|
+
# @overload to_uri_escape()
|
741
|
+
#
|
742
|
+
# @return [String]
|
743
|
+
#
|
744
|
+
def to_uri_escape(*args)
|
745
|
+
_to_uri(to_s(*args)).gsub('^', '%5E')
|
746
|
+
end
|
747
|
+
|
748
|
+
private
|
749
|
+
|
750
|
+
# URI要素化 - URI表現用のEscapeと frame の追加
|
751
|
+
#
|
752
|
+
# @param [String] date 日付の表現
|
753
|
+
#
|
754
|
+
# @return [String]
|
755
|
+
#
|
756
|
+
def _to_uri(date)
|
757
|
+
(date.gsub(/\./, '-').gsub(/%/, '@') + caret_frame).
|
758
|
+
gsub(When::Parts::Resource::IRIEncode) {|c| When::Parts::Resource::IRIEncodeTable[c]}
|
759
|
+
end
|
760
|
+
|
761
|
+
# caret 付きの frame 名
|
762
|
+
#
|
763
|
+
# @return [String]
|
764
|
+
#
|
765
|
+
# @note 暦年代付きかまたは frame がグレゴリオ暦の場合は空文字列を返す
|
766
|
+
#
|
767
|
+
def caret_frame
|
768
|
+
prefix = When::Parts::Resource.base_uri + 'CalendarTypes/'
|
769
|
+
path = frame.iri
|
770
|
+
return '' if @calendar_era_props || path == prefix + 'Gregorian'
|
771
|
+
path = path[prefix.length..-1] if path.index(prefix) == 0
|
772
|
+
'^^' + path
|
773
|
+
end
|
774
|
+
|
775
|
+
# strftime で扱う項の値を取得する
|
776
|
+
#
|
777
|
+
# @param [String] designator 項目名
|
778
|
+
# @param [String] locale 文字列化を行う場合の locale の指定(デフォルト to_s(代表値))
|
779
|
+
# @param [Integer] d 日付が'年月日'、時刻が'時分秒'でない表現のための桁位置変更指示
|
780
|
+
# [ 年月に付く場合 - 大きいほうに位置をずらす ]
|
781
|
+
# [ 分秒に付く場合 - 小さいほうに位置をずらす ]
|
782
|
+
# @param [Integer] e 月の省略名の文字数
|
783
|
+
#
|
784
|
+
# @return [designator に依存]
|
785
|
+
#
|
786
|
+
def _term(designator, locale=nil, d=0, e=3)
|
787
|
+
designator = When::Locale.translate(designator,locale)
|
788
|
+
case designator
|
789
|
+
# 現在のロケールにおける曜日の省略名
|
790
|
+
when 'a' ; When.Resource('_co:Common::Abbr_Day')[to_i % 7].translate(locale)
|
791
|
+
# 現在のロケールにおける曜日の完全な名前
|
792
|
+
when 'A' ; When.Resource('_co:Common::Week')[to_i % 7].label.translate(locale)
|
793
|
+
when 'b' ; (name(MONTH-d).translate(locale))[/\A.{1,#{e}}/] # 現在のロケールにおける月の省略名
|
794
|
+
when 'B' ; (name(MONTH-d).translate(locale)) # 現在のロケールにおける月の完全な名前
|
795
|
+
when 'C' ; year(d).div(100) # 世紀 (西暦年の上 2 桁)
|
796
|
+
when 'd' ; day(d) # 月内通算日
|
797
|
+
when 'E' ; Array(@calendar_era_props)[0].translate(locale)# 年号
|
798
|
+
when 'F' ; floor(DAY).to_m17n.translate(locale) # ISO 8601 形式の日付フォーマット
|
799
|
+
when 'G' ; cwyear(d) # ISO 8601 週単位表記の年
|
800
|
+
when 'g' ; cwyear(d) % 100 # ISO 8601 週単位表記の年の下2桁
|
801
|
+
when 'H' ; hour(d) # 24 時間表記での時
|
802
|
+
when 'I' ; (hour(d)-1) % 12 + 1 # 12 時間表記での時
|
803
|
+
when 'j' ; yday(d) # 年の初めから通算の日数
|
804
|
+
when 'm' ; month(d) # 月
|
805
|
+
when 'M' ; minute(d) # 分
|
806
|
+
when 'p' ; (AMPM[hour(d).to_i.div(12)].translate(locale)).upcase # 現在のロケールにおける「午前」「午後」に相当する文字列
|
807
|
+
when 'P' ; (AMPM[hour(d).to_i.div(12)].translate(locale)).downcase # 前項を小文字で表記
|
808
|
+
when 's' ; universal_time / Duration::SECOND # 紀元 (1970-01-01T00:00:00Z) からの秒数
|
809
|
+
when 'S' ; second(d) # 秒 (10 進数表記)
|
810
|
+
when 'u' ; cwday # 週の何番目の日か(月曜日を 1 とする)
|
811
|
+
when 'U' ; yweek(6, 7, d) # 年の初めからの通算の週番号(日曜日始まり)
|
812
|
+
when 'V' ; cweek(d) # ISO 8601 形式での年の始めからの週番号
|
813
|
+
when 'w' ; wday # 週の何番目の日 か(日曜日を 0 とする)
|
814
|
+
when 'W' ; yweek(0, 7, d) # 年の初めからの通算の週番号(月曜日始まり)
|
815
|
+
when 'y' ; year(d) % 100 # 西暦の下2桁 (世紀部分を含まない年)
|
816
|
+
when 'Y' ; year(d) # 世紀部分を含めた ( 4 桁の) 西暦年
|
817
|
+
when 'z' ; clock.to_basic # +hhmm や -hhmm の形式のタイムゾーン
|
818
|
+
when 'Z' ; When::Locale.translate(clock.tzname[0],locale) # タイムゾーンまたはゾーン名または省略名
|
819
|
+
else ; designator
|
820
|
+
end
|
821
|
+
end
|
822
|
+
|
823
|
+
# 指定の書式による多言語対応文字列化
|
824
|
+
#
|
825
|
+
# @param [String] locale 文字列化を行う locale
|
826
|
+
# @param [When::BasicTypes::M17n] pattern 書式
|
827
|
+
#
|
828
|
+
# @return [Array] 書式と文字列化項目からなる配列
|
829
|
+
#
|
830
|
+
def _strftime(locale, pattern, t)
|
831
|
+
format, *terms = t
|
832
|
+
pattern = pattern.translate(locale) if pattern.kind_of?(When::BasicTypes::M17n)
|
833
|
+
pattern.scan(/(%[O\d]*(?:\.(\d+))?.)|(.)/) do |c,e,s|
|
834
|
+
case c
|
835
|
+
when /\A%%/
|
836
|
+
format += '%%'
|
837
|
+
when /\A%/
|
838
|
+
action = TemporalPosition.format[c[-1..-1]]
|
839
|
+
case action
|
840
|
+
when Array
|
841
|
+
format += action[0]
|
842
|
+
terms << _term(action[1], locale, c[1..-2].to_i, e||3)
|
843
|
+
when String
|
844
|
+
action = action.translate(locale) if action.kind_of?(When::BasicTypes::M17n)
|
845
|
+
if (action =~ /%/)
|
846
|
+
format, *terms = _strftime(locale, action, [format] + terms)
|
847
|
+
else
|
848
|
+
format += action
|
849
|
+
end
|
850
|
+
end
|
851
|
+
else
|
852
|
+
format += s
|
853
|
+
end
|
854
|
+
end
|
855
|
+
[format] + terms
|
856
|
+
end
|
857
|
+
|
858
|
+
#
|
859
|
+
# 使用する When::CalendarNote を決定する
|
860
|
+
#
|
861
|
+
# options に副作用があることに注意
|
862
|
+
#
|
863
|
+
def _calendar_note(options)
|
864
|
+
calendar_note = options.delete(:calendar_note) if options.kind_of?(Hash)
|
865
|
+
calendar_note ||= @frame ? @frame.note : 'JulianDay'
|
866
|
+
When.CalendarNote(calendar_note)
|
867
|
+
end
|
868
|
+
end
|
869
|
+
|
870
|
+
class JulianDate
|
871
|
+
|
872
|
+
# 多言語対応文字列化 - ユリウス日を多言語対応文字列化する
|
873
|
+
#
|
874
|
+
# @param [Integer] precision どの桁まで多言語対応文字列化するか、分解能で指定する
|
875
|
+
#
|
876
|
+
# @return [When::BasicTypes::M17n]
|
877
|
+
#
|
878
|
+
def to_m17n(precision=@precision)
|
879
|
+
return m17n(to_s(precision))
|
880
|
+
end
|
881
|
+
|
882
|
+
# 文字列化 - ユリウス日を文字列化する
|
883
|
+
#
|
884
|
+
# @param [Integer] precision どの桁まで多言語対応文字列化するか、分解能で指定する
|
885
|
+
#
|
886
|
+
# @return [String]
|
887
|
+
#
|
888
|
+
def to_s(precision=@precision)
|
889
|
+
coordinate = (precision <= When::DAY) ? to_i : to_f
|
890
|
+
coordinate.to_s
|
891
|
+
end
|
892
|
+
end
|
893
|
+
|
894
|
+
class ClockTime
|
895
|
+
|
896
|
+
# 要素の多言語対応文字列化
|
897
|
+
#
|
898
|
+
# @param [Integer] index 多言語対応文字列化する要素の指定
|
899
|
+
# @param [When::BasicTypes::M17n] format 多言語対応文字列化の書式
|
900
|
+
#
|
901
|
+
# @return [When::BasicTypes::M17n]
|
902
|
+
#
|
903
|
+
def name(index, format=nil)
|
904
|
+
digit = _digit(index) {|digit| digit > DAY}
|
905
|
+
coordinate = @clk_time[digit]
|
906
|
+
return m17n(format % coordinate) if format
|
907
|
+
|
908
|
+
indices = @frame.indices[digit-1]
|
909
|
+
if indices
|
910
|
+
trunk = indices.trunk
|
911
|
+
branch = indices.branch
|
912
|
+
end
|
913
|
+
format = branch ? m17n("%02d:") : "%02d"
|
914
|
+
return m17n(format % coordinate) unless trunk
|
915
|
+
trunk = trunk[coordinate * 1]
|
916
|
+
return m17n(trunk) unless branch
|
917
|
+
return trunk.prefix(branch[coordinate * 0])
|
918
|
+
end
|
919
|
+
|
920
|
+
# 多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する
|
921
|
+
#
|
922
|
+
# @param [Integer] precision どの桁まで多言語対応文字列化するか、分解能で指定する
|
923
|
+
#
|
924
|
+
# @return [When::BasicTypes::M17n]
|
925
|
+
#
|
926
|
+
def to_m17n(precision=@precision)
|
927
|
+
time = m17n('T' + _time_to_s(precision))
|
928
|
+
if @frame
|
929
|
+
time += @frame.zone unless Clock.is_local_time_set? && @frame.equal?(Clock.local_time)
|
930
|
+
end
|
931
|
+
return time
|
932
|
+
end
|
933
|
+
|
934
|
+
# 文字列化 - When.exe Standard Representation により文字列化する
|
935
|
+
#
|
936
|
+
# @param [Integer] precision どの桁まで多言語対応文字列化するか、分解能で指定する
|
937
|
+
#
|
938
|
+
# @return [String]
|
939
|
+
#
|
940
|
+
def to_s(precision=@precision)
|
941
|
+
time = 'T' + _time_to_s(precision)
|
942
|
+
if @frame
|
943
|
+
time += @frame.zone unless Clock.is_local_time_set? && @frame.equal?(Clock.local_time)
|
944
|
+
end
|
945
|
+
return time
|
946
|
+
end
|
947
|
+
|
948
|
+
# 時
|
949
|
+
#
|
950
|
+
# @param [Integer] d 時刻が'時分秒'でない表現のための桁位置変更指示(小さいほうに位置をずらす)
|
951
|
+
#
|
952
|
+
# @return [Numeric] 自身の「時」
|
953
|
+
#
|
954
|
+
def hour(d=0)
|
955
|
+
@clk_time[HOUR+d]
|
956
|
+
end
|
957
|
+
|
958
|
+
# 分
|
959
|
+
#
|
960
|
+
# @param [Integer] d 時刻が'時分秒'でない表現のための桁位置変更指示(小さいほうに位置をずらす)
|
961
|
+
#
|
962
|
+
#
|
963
|
+
# @return [Numeric] 自身の「分」
|
964
|
+
#
|
965
|
+
def minute(d=0)
|
966
|
+
@clk_time[MINUTE+d]
|
967
|
+
end
|
968
|
+
alias :min :minute
|
969
|
+
|
970
|
+
# 秒
|
971
|
+
#
|
972
|
+
# @param [Integer] d 時刻が'時分秒'でない表現のための桁位置変更指示(小さいほうに位置をずらす)
|
973
|
+
#
|
974
|
+
#
|
975
|
+
# @return [Numeric] 自身の「秒」
|
976
|
+
#
|
977
|
+
def second(d=0)
|
978
|
+
@clk_time[SECOND+d]
|
979
|
+
end
|
980
|
+
alias :sec :second
|
981
|
+
|
982
|
+
#protected
|
983
|
+
#
|
984
|
+
# 時間帯以外の部分の文字列化
|
985
|
+
#
|
986
|
+
# @param [Integer] precision どの桁まで多言語対応文字列化するか、分解能で指定する
|
987
|
+
#
|
988
|
+
# @return [String]
|
989
|
+
#
|
990
|
+
# @private
|
991
|
+
def _time_to_s(precision=@precision)
|
992
|
+
terms = []
|
993
|
+
format = ''
|
994
|
+
format += Pair::DL2[@clk_time[0] * 0] || ':' if @frame.pair[0] || @clk_time[0].kind_of?(Pair)
|
995
|
+
|
996
|
+
# 時分
|
997
|
+
digits = [@clk_time.length-2, precision].min
|
998
|
+
if digits > 0
|
999
|
+
terms += @clk_time[1..-1]
|
1000
|
+
format += "%02d:" * digits
|
1001
|
+
format = format[0..-2] if precision == digits
|
1002
|
+
end
|
1003
|
+
|
1004
|
+
# 秒
|
1005
|
+
digits = [precision - @clk_time.length + 1, STRING-SECOND].min
|
1006
|
+
if digits == 0
|
1007
|
+
format += "%02d"
|
1008
|
+
elsif digits > 0
|
1009
|
+
factor = 10**digits
|
1010
|
+
terms[-1] = ((@clk_time[-1] + 1E-6) * factor).floor.to_f / factor # 切り捨て(10で割る丸めガードあり)
|
1011
|
+
format += "%02.#{digits}f"
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
# 結果
|
1015
|
+
time = Pair._format([format] + terms)
|
1016
|
+
time.sub(/([^\d])(\d)\./, '\10\2.')
|
1017
|
+
end
|
1018
|
+
|
1019
|
+
#
|
1020
|
+
# to_h のための要素生成
|
1021
|
+
# @private
|
1022
|
+
def _to_hash_value(options={})
|
1023
|
+
clk_time.map {|e| _m17n_form(e, options) }
|
1024
|
+
end
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
class CalDate
|
1028
|
+
|
1029
|
+
#
|
1030
|
+
# 暦法名
|
1031
|
+
#
|
1032
|
+
# @return [Array] ( name, epoch, reverse, go back )
|
1033
|
+
# - name 暦法または暦年代 ({When::TM::Calendar}, {When::TM::CalendarEra})
|
1034
|
+
# - epoch 暦元 (Integer)
|
1035
|
+
# - reverse 暦年の順序 (Boolean)
|
1036
|
+
# [ false, nil 昇順 ]
|
1037
|
+
# [ true 降順 ]
|
1038
|
+
# - go back 参照イベントより前の暦日か(Boolean)
|
1039
|
+
# [ false, nil 否 ]
|
1040
|
+
# [ true 然り ]
|
1041
|
+
#
|
1042
|
+
def calendar_name
|
1043
|
+
void, epoch, reverse, back = @calendar_era_props
|
1044
|
+
name = [@calendar_era || @frame, epoch, reverse, back]
|
1045
|
+
name.pop until name[-1]
|
1046
|
+
return name
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
#
|
1050
|
+
# 参照ラベル
|
1051
|
+
#
|
1052
|
+
# @return [When::BasicTypes::M17n]
|
1053
|
+
#
|
1054
|
+
def reference_label
|
1055
|
+
return @calendar_era.hierarchy.map {|e| e.label} if @calendar_era
|
1056
|
+
return [@frame.label] if @frame.label
|
1057
|
+
[When::BasicTypes::M17n.new(@frame.class.to_s.split(/::/)[-1])]
|
1058
|
+
end
|
1059
|
+
|
1060
|
+
#
|
1061
|
+
# 時間座標値
|
1062
|
+
#
|
1063
|
+
# @return [Numeric] オブジェクトの precision に対応する時間座標の値
|
1064
|
+
#
|
1065
|
+
def coordinate
|
1066
|
+
raise ArgumentError, "Presicion not defined" unless When::Coordinates::PERIOD_NAME[@precision]
|
1067
|
+
self[@precision]
|
1068
|
+
end
|
1069
|
+
|
1070
|
+
#
|
1071
|
+
# 自身に所属する When::TM::CalDate オブジェクト
|
1072
|
+
#
|
1073
|
+
# @return [Array<When::TM::CalDate>] 自身に所属する precision+1 の分解能のオブジェクトの Array
|
1074
|
+
#
|
1075
|
+
# @note precision が 0(When::DAY) の場合、空 Array を返す
|
1076
|
+
#
|
1077
|
+
def member
|
1078
|
+
raise ArgumentError, "Presicion not defined" unless When::Coordinates::PERIOD_NAME[@precision]
|
1079
|
+
child = floor(@precision+1)
|
1080
|
+
list = []
|
1081
|
+
while self == child
|
1082
|
+
list << child
|
1083
|
+
child = child.succ
|
1084
|
+
end
|
1085
|
+
list
|
1086
|
+
end
|
1087
|
+
|
1088
|
+
#
|
1089
|
+
# Hash 化
|
1090
|
+
#
|
1091
|
+
# @param [String] options { :notes => String } という Hash の指定と等価
|
1092
|
+
# @param [Integer] options { :indices => Integer } という Hash の指定と等価
|
1093
|
+
# @param [Hash] options 下記のとおり
|
1094
|
+
# @option options [When::CalendarNote, String] :calendar_note 暦注を計算する暦注オブジェクトまたはそのIRI
|
1095
|
+
# @option options [Object] その他のキー {When::CalendarNote#notes} を参照
|
1096
|
+
#
|
1097
|
+
# @return [Hash]
|
1098
|
+
# - :calendar calendar_name の結果 ( name, epoch, reverse, go back )
|
1099
|
+
# - name 暦法または暦年代 ({When::TM::Calendar}, {When::TM::CalendarEra})
|
1100
|
+
# - epoch 暦元 (Integer)
|
1101
|
+
# - reverse 暦年の順序 (Boolean)
|
1102
|
+
# [ false, nil 昇順 ]
|
1103
|
+
# [ true 降順 ]
|
1104
|
+
# - go back 参照イベントより前の暦日か(Boolean)
|
1105
|
+
# [ false, nil 否 ]
|
1106
|
+
# [ true 然り ]
|
1107
|
+
# - :cal_date cal_date の内容 (year, month, day)
|
1108
|
+
# [ year - 年 ({Numeric}) ]
|
1109
|
+
# [ month - 月 ({Numeric}) ]
|
1110
|
+
# [ day - 日 ({Numeric}) ]
|
1111
|
+
# - :clk_time to_clock_time の結果 ( 日, 時, 分, 秒 )
|
1112
|
+
# - :notes Hash (の Array (の Array)) - _notes(options)
|
1113
|
+
#
|
1114
|
+
def _to_h(options={})
|
1115
|
+
super.update({:cal_date=>@cal_date})
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
# 要素の多言語対応文字列化
|
1119
|
+
#
|
1120
|
+
# @param [Integer] index 多言語対応文字列化する要素の指定
|
1121
|
+
# @param [When::BasicTypes::M17n] format 多言語対応文字列化の書式
|
1122
|
+
#
|
1123
|
+
# @return [When::BasicTypes::M17n]
|
1124
|
+
#
|
1125
|
+
def name(index, format=nil)
|
1126
|
+
digit = _digit(index) {|digit| digit <= DAY}
|
1127
|
+
coordinate = @cal_date[digit-1]
|
1128
|
+
return m17n(format % coordinate) if format
|
1129
|
+
|
1130
|
+
indices = @frame.indices[digit-1]
|
1131
|
+
if indices
|
1132
|
+
trunk = indices.trunk
|
1133
|
+
branch = indices.branch
|
1134
|
+
end
|
1135
|
+
format = branch ? m17n("%02d-") : "%02d"
|
1136
|
+
return m17n(format % coordinate) unless trunk
|
1137
|
+
trunk = trunk[coordinate * 1]
|
1138
|
+
return m17n(trunk) unless branch
|
1139
|
+
return trunk.prefix(branch[coordinate * 0||0])
|
1140
|
+
end
|
1141
|
+
|
1142
|
+
# 日
|
1143
|
+
#
|
1144
|
+
# @param [Integer] d 日付が'年月日'でない表現のための桁位置変更指示(大きいほうに位置をずらす)
|
1145
|
+
#
|
1146
|
+
# @return [Numeric] 自身の「日」
|
1147
|
+
#
|
1148
|
+
def day(d=0)
|
1149
|
+
@cal_date[DAY-1-d]
|
1150
|
+
end
|
1151
|
+
|
1152
|
+
# 月内通日
|
1153
|
+
#
|
1154
|
+
# @param [Integer] d 日付が'年月日'でない表現のための桁位置変更指示(大きいほうに位置をずらす)
|
1155
|
+
#
|
1156
|
+
# @return [Numeric] 自身の「月内通日」(1始まり)
|
1157
|
+
#
|
1158
|
+
def mday(d=0)
|
1159
|
+
to_i - floor(MONTH-d).to_i + 1
|
1160
|
+
end
|
1161
|
+
|
1162
|
+
# 年内通日
|
1163
|
+
#
|
1164
|
+
# @param [Integer] d 日付が'年月日'でない表現のための桁位置変更指示(大きいほうに位置をずらす)
|
1165
|
+
#
|
1166
|
+
# @return [Numeric] 自身の「年内通日」(1始まり)
|
1167
|
+
#
|
1168
|
+
def yday(d=0)
|
1169
|
+
to_i - floor(YEAR-d).to_i + 1
|
1170
|
+
end
|
1171
|
+
|
1172
|
+
# 七曜
|
1173
|
+
#
|
1174
|
+
# @return [Numeric] 自身の「七曜」(日曜 0 始まり)
|
1175
|
+
#
|
1176
|
+
def wday
|
1177
|
+
(to_i + 1) % 7
|
1178
|
+
end
|
1179
|
+
|
1180
|
+
# 七曜(暦週)
|
1181
|
+
#
|
1182
|
+
# @return [Numeric] 自身の「七曜」(月曜 1 始まり)
|
1183
|
+
#
|
1184
|
+
def cwday
|
1185
|
+
(to_i % 7) + 1
|
1186
|
+
end
|
1187
|
+
|
1188
|
+
# 暦週
|
1189
|
+
#
|
1190
|
+
# @param [Integer] d 日付が'年月日'でない表現のための桁位置変更指示(大きいほうに位置をずらす)
|
1191
|
+
#
|
1192
|
+
# @return [Numeric] 自身の「暦週」
|
1193
|
+
#
|
1194
|
+
def cweek(d=0)
|
1195
|
+
[1,0,-1].each do |i|
|
1196
|
+
start = ((self + PeriodDuration.new(i, YEAR-d)).floor(YEAR-d,DAY) + PeriodDuration.new(4, DAY)) & Residue.new(0,7,-1)
|
1197
|
+
return ((to_i - start.to_i).div 7) + 1 if self >= start
|
1198
|
+
end
|
1199
|
+
raise IndexError, 'Cannot decide year number'
|
1200
|
+
end
|
1201
|
+
|
1202
|
+
# 月内通週
|
1203
|
+
#
|
1204
|
+
# @param [Integer] w 週の最初の曜日(0:月,.., 6:日)
|
1205
|
+
# @param [Integer] m 一週間の日数
|
1206
|
+
# @param [Integer] d 日付が'年月日'でない表現のための桁位置変更指示(大きいほうに位置をずらす)
|
1207
|
+
#
|
1208
|
+
# @return [Numeric] 自身の「月内通週」(その月に完全に含まれる最初の週を1とする)
|
1209
|
+
#
|
1210
|
+
def mweek(w=6, m=7, d=0)
|
1211
|
+
1 + (to_i - (floor(MONTH-d,DAY) & Residue.new(w,m)).to_i).div(7)
|
1212
|
+
end
|
1213
|
+
|
1214
|
+
# 年内通週
|
1215
|
+
#
|
1216
|
+
# @param [Integer] w 週の最初の曜日(0:月,.., 6:日)
|
1217
|
+
# @param [Integer] m 一週間の日数
|
1218
|
+
# @param [Integer] d 日付が'年月日'でない表現のための桁位置変更指示(大きいほうに位置をずらす)
|
1219
|
+
#
|
1220
|
+
# @return [Numeric]
|
1221
|
+
# 自身の「年内通週」(その年に完全に含まれる最初の週を1とする)
|
1222
|
+
#
|
1223
|
+
def yweek(w=6, m=7, d=0)
|
1224
|
+
1 + (to_i - (floor(YEAR-d,DAY) & Residue.new(w,m)).to_i).div(7)
|
1225
|
+
end
|
1226
|
+
|
1227
|
+
# 月
|
1228
|
+
#
|
1229
|
+
# @param [Integer] d 日付が'年月日'でない表現のための桁位置変更指示(大きいほうに位置をずらす)
|
1230
|
+
#
|
1231
|
+
# @return [Numeric] 自身の「月」
|
1232
|
+
#
|
1233
|
+
def month(d=0)
|
1234
|
+
@cal_date[MONTH-1-d]
|
1235
|
+
end
|
1236
|
+
alias :mon :month
|
1237
|
+
|
1238
|
+
# 年内通月
|
1239
|
+
#
|
1240
|
+
# @param [Integer] d1 日付が'年月日'でない表現のための桁位置変更指示-年用(大きいほうに位置をずらす)
|
1241
|
+
# @param [Integer] d2 日付が'年月日'でない表現のための桁位置変更指示-月用(大きいほうに位置をずらす)
|
1242
|
+
#
|
1243
|
+
# @return [Numeric] 自身の「年内通月」(1始まり)
|
1244
|
+
#
|
1245
|
+
def ymon(d1=0, d2=0)
|
1246
|
+
current = floor(YEAR-d1, MONTH-d2)
|
1247
|
+
@frame._length(@cal_date[(YEAR-1-d1)...(MONTH-1-d2)]).times do |i|
|
1248
|
+
return i+1 if current == self
|
1249
|
+
current = current.succ
|
1250
|
+
end
|
1251
|
+
raise IndexError, 'Cannot decide month number'
|
1252
|
+
end
|
1253
|
+
|
1254
|
+
# 年
|
1255
|
+
#
|
1256
|
+
# @param [Integer] d 日付が'年月日'でない表現のための桁位置変更指示(大きいほうに位置をずらす)
|
1257
|
+
#
|
1258
|
+
# @return [Numeric] 自身の「年」
|
1259
|
+
#
|
1260
|
+
def year(d=0)
|
1261
|
+
@cal_date[YEAR-1-d]
|
1262
|
+
end
|
1263
|
+
|
1264
|
+
# 暦週の年
|
1265
|
+
#
|
1266
|
+
# @param [Integer] d 日付が'年月日'でない表現のための桁位置変更指示(大きいほうに位置をずらす)
|
1267
|
+
#
|
1268
|
+
# @return [Numeric] 自身の「暦週の年」
|
1269
|
+
#
|
1270
|
+
def cwyear(d=0)
|
1271
|
+
[1,0,-1].each do |i|
|
1272
|
+
start = ((self + PeriodDuration.new(i, YEAR-d)).floor(YEAR-d,DAY) + PeriodDuration.new(4, DAY)) & Residue.new(0,7,-1)
|
1273
|
+
return year(d)+i if self >= start
|
1274
|
+
end
|
1275
|
+
raise IndexError, 'Cannot decide year number'
|
1276
|
+
end
|
1277
|
+
|
1278
|
+
# 多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する
|
1279
|
+
#
|
1280
|
+
# @param [Integer] precision どの桁まで多言語対応文字列化するか、分解能で指定する
|
1281
|
+
# @param [false] round 常に切り捨てる(DateAndTimeとの互換性のためのダミーの引数)
|
1282
|
+
#
|
1283
|
+
# @return [When::BasicTypes::M17n]
|
1284
|
+
#
|
1285
|
+
def to_m17n(precision=@precision, round=false)
|
1286
|
+
date = m17n(_date_to_s(precision))
|
1287
|
+
return date unless @calendar_era
|
1288
|
+
return _parent_labels.inject(m17n(calendar_era_name)) {|era_name, parent|
|
1289
|
+
era_name.prefix(m17n(parent) + '::')
|
1290
|
+
} + date
|
1291
|
+
end
|
1292
|
+
|
1293
|
+
# 文字列化 - When.exe Standard Representation により文字列化する
|
1294
|
+
#
|
1295
|
+
# @param [Integer] precision どの桁まで多言語対応文字列化するか、分解能で指定する
|
1296
|
+
# @param [false] round 常に切り捨てる(DateAndTimeとの互換性のためのダミーの引数)
|
1297
|
+
#
|
1298
|
+
# @return [String]
|
1299
|
+
#
|
1300
|
+
def to_s(precision=@precision, round=false)
|
1301
|
+
date = _date_to_s(precision)
|
1302
|
+
return date unless @calendar_era
|
1303
|
+
return _parent_labels.inject(calendar_era_name.to_s) {|era_name, parent|
|
1304
|
+
parent.to_s + '::' + era_name
|
1305
|
+
} + date
|
1306
|
+
end
|
1307
|
+
|
1308
|
+
# event を 文字列化 - 日時で与えられた event を文字列化する
|
1309
|
+
#
|
1310
|
+
# @param [When::TM::TemporalPosition] other 時系の歩度を比較する基準(nilは比較しない)
|
1311
|
+
# @param [Hash] options 下記の通り
|
1312
|
+
# @option options [Numeric] :precision イベント名(イベント)出力の場合の時刻の丸め位置(nilなら丸めない)
|
1313
|
+
# @option options [Symbol] :method 変換に用いるメソッド(:to_m17n のとき多言語文字列化)
|
1314
|
+
#
|
1315
|
+
# @return [String]
|
1316
|
+
#
|
1317
|
+
# @note
|
1318
|
+
# events 配列なし - 日時をそのまま文字列化
|
1319
|
+
# 日時の精度が日より細かい - イベント名(イベント時刻)
|
1320
|
+
# 日時の精度が日 - イベント名(当日までの経過日数)
|
1321
|
+
#
|
1322
|
+
def _event_form(other=nil, options={})
|
1323
|
+
return options[:method]==:to_m17n ? to_m17n : self unless events
|
1324
|
+
return events[0] + '(' + _clk_time_for_inspect(options[:precision]).
|
1325
|
+
to_s(options[:precision] || precision)[/[:*=0-9]+/] + ')' if precision > When::DAY
|
1326
|
+
return events[0] unless other
|
1327
|
+
other = JulianDate.dynamical_time(other.dynamical_time,
|
1328
|
+
{:time_standard=>time_standard}) unless time_standard.rate_of_clock == other.time_standard.rate_of_clock
|
1329
|
+
events[0] + '(' + (other.to_i - to_i).to_s + ')'
|
1330
|
+
end
|
1331
|
+
|
1332
|
+
private
|
1333
|
+
|
1334
|
+
# 日付の年号に曖昧性がある場合の親年号の label の Array
|
1335
|
+
#
|
1336
|
+
# @return [Array<String>]
|
1337
|
+
#
|
1338
|
+
def _parent_labels
|
1339
|
+
return [] unless (area = When::TM::CalendarEra[nil]) &&
|
1340
|
+
(period = area[nil])
|
1341
|
+
list = []
|
1342
|
+
era = @calendar_era
|
1343
|
+
while (labels = period[era.label.to_s]) &&
|
1344
|
+
(epoch = labels[era.epoch_year]) &&
|
1345
|
+
(epoch.size > 1) &&
|
1346
|
+
(parent = era.parent).respond_to?(:epoch_year)
|
1347
|
+
list << parent.label
|
1348
|
+
era = parent
|
1349
|
+
end
|
1350
|
+
list
|
1351
|
+
end
|
1352
|
+
|
1353
|
+
# 日付の年号以外の部分を文字列化する
|
1354
|
+
#
|
1355
|
+
# @param [Integer] precision どの桁まで多言語対応文字列化するか、分解能で指定する
|
1356
|
+
#
|
1357
|
+
# @return [String]
|
1358
|
+
#
|
1359
|
+
def _date_to_s(precision)
|
1360
|
+
# 準備
|
1361
|
+
precision = [precision, 1 - @cal_date.length].max
|
1362
|
+
precision = [precision, DAY].min
|
1363
|
+
terms = []
|
1364
|
+
ext_dg = [(@extra_year_digits||1).to_i, 0].max
|
1365
|
+
year_dg = @frame.indices.length <= 2 ? 4 : 2
|
1366
|
+
|
1367
|
+
# 年
|
1368
|
+
year_by_epoch = @cal_date[0]
|
1369
|
+
if @calendar_era_props
|
1370
|
+
era, epoch, reverse = @calendar_era_props
|
1371
|
+
year_in_term = reverse ? -year_by_epoch : year_by_epoch
|
1372
|
+
year_by_calendar = epoch + year_by_epoch if epoch
|
1373
|
+
terms << year_in_term
|
1374
|
+
format = (0..99) === (year_in_term * 1) ? "%02d." : "%0#{year_dg}d."
|
1375
|
+
if year_by_calendar && year_by_calendar != year_in_term
|
1376
|
+
terms << (year_by_calendar * 1)
|
1377
|
+
format += "(%0#{year_dg}d)"
|
1378
|
+
end
|
1379
|
+
else
|
1380
|
+
terms << year_by_epoch
|
1381
|
+
format = (0..(10**year_dg-1)) === (year_by_epoch * 1) ? "%0#{year_dg}d." : "%+0#{5+ext_dg}d."
|
1382
|
+
end
|
1383
|
+
|
1384
|
+
# 月日
|
1385
|
+
((1-@cal_date.length)..-1).each do |i|
|
1386
|
+
break if (i >= precision)
|
1387
|
+
terms << @cal_date[i]
|
1388
|
+
format += "%02d."
|
1389
|
+
end
|
1390
|
+
|
1391
|
+
# 結果
|
1392
|
+
date = Pair._format([format] + terms)
|
1393
|
+
date.sub!(/([^\d])\(([-+\d]+)\)/, '(\2)\1') if era
|
1394
|
+
date = date[0..-2] unless @frame.pair[precision-1] || date[-1..-1] != '.'
|
1395
|
+
date.gsub!(/\./, '-') if (@frame.indices.length <= 3) && !era
|
1396
|
+
return date
|
1397
|
+
end
|
1398
|
+
end
|
1399
|
+
|
1400
|
+
class DateAndTime < CalDate
|
1401
|
+
|
1402
|
+
# 要素の多言語対応文字列化
|
1403
|
+
#
|
1404
|
+
# @param [Integer] index 多言語対応文字列化する要素の指定
|
1405
|
+
# @param [When::BasicTypes::M17n] format 多言語対応文字列化の書式
|
1406
|
+
#
|
1407
|
+
# @return [When::BasicTypes::M17n]
|
1408
|
+
#
|
1409
|
+
def name(index, format=nil)
|
1410
|
+
digit = _digit(index)
|
1411
|
+
(digit <= DAY) ? super : @clk_time.name(digit, format)
|
1412
|
+
end
|
1413
|
+
|
1414
|
+
# 多言語対応文字列化 - When.exe Standard Representation により多言語対応文字列化する
|
1415
|
+
#
|
1416
|
+
# @param [Integer] precision どの桁まで多言語対応文字列化するか、分解能で指定する
|
1417
|
+
# @param [true, false] round 指定の桁までで丸める(true)か, 切り捨てる(false)か
|
1418
|
+
# @note 丸めるのは precision が When::DAY よりも高精度の場合のみである
|
1419
|
+
#
|
1420
|
+
# @return [When::BasicTypes::M17n]
|
1421
|
+
#
|
1422
|
+
def to_m17n(precision=@precision, round=false)
|
1423
|
+
super + _clk_time_for_inspect(round ? precision : nil).to_m17n(precision)
|
1424
|
+
end
|
1425
|
+
|
1426
|
+
# 文字列化 -When.exe Standard Representation により文字列化する
|
1427
|
+
#
|
1428
|
+
# @param [Integer] precision どの桁まで多言語対応文字列化するか、分解能で指定する
|
1429
|
+
# @param [true, false] round 指定の桁までで丸める(true)か, 切り捨てる(false)か
|
1430
|
+
# @note 丸めるのは precision が When::DAY よりも高精度の場合のみである
|
1431
|
+
#
|
1432
|
+
# @return [String]
|
1433
|
+
#
|
1434
|
+
def to_s(precision=@precision, round=false)
|
1435
|
+
super + _clk_time_for_inspect(round ? precision : nil).to_s(precision)
|
1436
|
+
end
|
1437
|
+
|
1438
|
+
# 出力に使用する clk_time の作成
|
1439
|
+
def _clk_time_for_inspect(precision)
|
1440
|
+
return @clk_time unless precision && precision > When::DAY
|
1441
|
+
base = self + When::TM::Duration.new(@clk_time.frame._round_value(precision))
|
1442
|
+
base.clk_time.clk_time[When::HOUR] = @clk_time.clk_time[When::HOUR] + 1 unless self.to_i == base.to_i
|
1443
|
+
return base.clk_time
|
1444
|
+
end
|
1445
|
+
private :_clk_time_for_inspect
|
1446
|
+
|
1447
|
+
# 時
|
1448
|
+
#
|
1449
|
+
# @param [Integer] d 時刻が'時分秒'でない表現のための桁位置変更指示(小さいほうに位置をずらす)
|
1450
|
+
#
|
1451
|
+
# @return [Numeric] 自身の「時」
|
1452
|
+
#
|
1453
|
+
def hour(d=0)
|
1454
|
+
@clk_time.hour(d)
|
1455
|
+
end
|
1456
|
+
|
1457
|
+
# 分
|
1458
|
+
#
|
1459
|
+
# @param [Integer] d 時刻が'時分秒'でない表現のための桁位置変更指示(小さいほうに位置をずらす)
|
1460
|
+
#
|
1461
|
+
# @return [Numeric] 自身の「分」
|
1462
|
+
#
|
1463
|
+
def minute(d=0)
|
1464
|
+
@clk_time.minute(d)
|
1465
|
+
end
|
1466
|
+
alias :min :minute
|
1467
|
+
|
1468
|
+
# 秒
|
1469
|
+
#
|
1470
|
+
# @param [Integer] d 時刻が'時分秒'でない表現のための桁位置変更指示(小さいほうに位置をずらす)
|
1471
|
+
#
|
1472
|
+
# @return [Numeric] 自身の「秒」
|
1473
|
+
#
|
1474
|
+
def second(d=0)
|
1475
|
+
@clk_time.second(d)
|
1476
|
+
end
|
1477
|
+
alias :sec :second
|
1478
|
+
end
|
1479
|
+
end
|
1480
|
+
end
|