-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathDate.resi
1360 lines (1076 loc) · 35.2 KB
/
Date.resi
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
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
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
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
/***
Functions for interacting with JavaScript Dates.
*/
/**
A type representing a JavaScript date.
*/
type t = Js.Date.t
/**
Time, in milliseconds, since / until the UNIX epoch (January 1, 1970 00:00:00 UTC).
Positive numbers represent dates after, negative numbers dates before epoch.
*/
type msSinceEpoch = float
/**
A type representing date time format options.
Note: There are some properties missing:
- fractionalSecondDigits
- dayPeriod
- calendar
- numberingSystem
- localeMatcher
- timeZone
- hour12
- hourCycle
- formatMatcher
See full spec at https://tc39.es/ecma402/#datetimeformat-objects
*/
type localeOptions = {
dateStyle?: [#full | #long | #medium | #short],
timeStyle?: [#full | #long | #medium | #short],
weekday?: [#long | #narrow | #short],
era?: [#long | #narrow | #short],
year?: [#"2-digit" | #numeric],
month?: [#"2-digit" | #long | #narrow | #numeric | #short],
day?: [#"2-digit" | #numeric],
hour?: [#"2-digit" | #numeric],
minute?: [#"2-digit" | #numeric],
second?: [#"2-digit" | #numeric],
timeZoneName?: [#long | #short],
}
/**
`make()`
Creates a date object with the current date time as value.
## Examples
```rescript
Date.make()
```
*/
@new
external make: unit => t = "Date"
/**
`fromString(dateTimeString)`
Creates a date object from given date time string.
The string has to be in the ISO 8601 format YYYY-MM-DDTHH:mm:ss.sssZ (https://tc39.es/ecma262/#sec-date-time-string-format).
Invalid date time strings will create invalid dates.
You can use the result like any valid date, but many functions like `toString` will return "Invalid Date" or functions like `Date.getTime` will return NaN.
## Examples
```rescript
Date.fromString("2023") // 2023-01-01T00:00:00.000Z
Date.fromString("2023-02-20") // 2023-02-20T00:00:00.000Z
Date.fromString("2023-02-20T16:40:00.00Z") // 2023-02-20T16:40:00.000Z
Date.fromString("") // Invalid Date
Date.fromString("")->Date.getTime // NaN
```
*/
@new
external fromString: string => t = "Date"
/**
`fromTime(msSinceEpoch)`
Creates a date object from the given time in milliseconds since / until UNIX epoch (January 1, 1970 00:00:00 UTC).
Positive numbers create dates after epoch, negative numbers create dates before epoch.
## Examples
```rescript
Date.fromTime(0.0)
// 1970-01-01T00:00:00.000Z
Date.fromTime(-86_400_000.0)
// 1969-12-31T00:00:00.000Z
Date.fromTime(86_400_000.0)
// 1970-01-02T00:00:00.000Z
```
*/
@new
external fromTime: msSinceEpoch => t = "Date"
/**
Creates a date object with the given year and month.
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.makeWithYM(~year=2023, ~month=0)
// 2023-01-01T00:00:00.000Z
Date.makeWithYM(~year=2023, ~month=11)
// 2023-12-01T00:00:00.000Z
Date.makeWithYM(~year=2023, ~month=12)
// 2024-01-01T00:00:00.000Z
Date.makeWithYM(~year=2023, ~month=-1)
// 2022-12-01T00:00:00.000Z
// Note: The output depends on your local time zone.
// In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`)
```
*/
@new
external makeWithYM: (~year: int, ~month: int) => t = "Date"
/**
Creates a date object with the given year, month and date (day of month).
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.makeWithYMD(~year=2023, ~month=1, ~date=20)
// 2023-02-20T00:00:00.000Z
Date.makeWithYMD(~year=2023, ~month=1, ~date=-1)
// 2022-11-29T00:00:00.000Z
Date.makeWithYMD(~year=2023, ~month=1, ~date=29)
// 2023-03-01T00:00:00.000Z
```
*/
@new
external makeWithYMD: (~year: int, ~month: int, ~date: int) => t = "Date"
/**
Creates a date object with the given year, month, date (day of month) and hours.
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16)
// 2023-02-20T16:00:00.000Z
Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24)
// 2023-02-21T00:00:00.000Z
Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1)
// 2023-02-19T23:00:00.000Z
// Note: The output depends on your local time zone.
// In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`)
```
*/
@new
external makeWithYMDH: (~year: int, ~month: int, ~date: int, ~hours: int) => t = "Date"
/**
Creates a date object with the given year, month, date (day of month), hours and minutes.
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40)
// 2023-02-20T16:40:00.000Z
Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60)
// 2023-02-20T17:00:00.000Z
Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1)
// 2023-02-20T15:59:00.000Z
// Note: The output depends on your local time zone.
// In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`)
```
*/
@new
external makeWithYMDHM: (~year: int, ~month: int, ~date: int, ~hours: int, ~minutes: int) => t =
"Date"
/**
Creates a date object with the given year, month, date (day of month), hours, minutes and seconds.
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0)
// 2023-02-20T16:40:00.000Z
Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60)
// 2023-02-20T16:41:00.000Z
Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1)
// 2023-02-20T16:39:59.000Z
// Note: The output depends on your local time zone.
// In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`)
```
*/
@new
external makeWithYMDHMS: (
~year: int,
~month: int,
~date: int,
~hours: int,
~minutes: int,
~seconds: int,
) => t = "Date"
/**
Creates a date object with the given year, month, date (day of month), hours, minutes, seconds and milliseconds.
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=0)
// 2023-02-20T16:40:00.000Z
Date.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=1000)
// 2023-02-20T16:40:01.000Z
Date.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=-1)
// 2023-02-20T16:39:59.999Z
// Note: The output depends on your local time zone.
// In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`)
```
*/
@new
external makeWithYMDHMSM: (
~year: int,
~month: int,
~date: int,
~hours: int,
~minutes: int,
~seconds: int,
~milliseconds: int,
) => t = "Date"
module UTC: {
/**
Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC).
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.UTC.makeWithYM(~year=2023, ~month=0)
// 1672531200000
Date.UTC.makeWithYM(~year=2023, ~month=11)
// 1701388800000
Date.UTC.makeWithYM(~year=2023, ~month=12)
// 1704067200000
Date.UTC.makeWithYM(~year=2023, ~month=-1)
// 1669852800000
```
*/
@val
external makeWithYM: (~year: int, ~month: int) => msSinceEpoch = "Date.UTC"
/**
Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC).
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=20)
// 1676851200000
Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=-1)
// 1675036800000
Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=29)
// 1677628800000
```
*/
@val
external makeWithYMD: (~year: int, ~month: int, ~date: int) => msSinceEpoch = "Date.UTC"
/**
Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC).
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16)
// 1676908800000
Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24)
// 1676937600000
Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1)
// 1676847600000
```
*/
@val
external makeWithYMDH: (~year: int, ~month: int, ~date: int, ~hours: int) => msSinceEpoch =
"Date.UTC"
/**
Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC).
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40)
// 1676911200000
Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60)
// 1676912400000
Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1)
// 1676908740000
```
*/
@val
external makeWithYMDHM: (
~year: int,
~month: int,
~date: int,
~hours: int,
~minutes: int,
) => msSinceEpoch = "Date.UTC"
/**
Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC).
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0)
// 1676911200000
Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60)
// 1676911260000
Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1)
// 1676911199000
```
*/
@val
external makeWithYMDHMS: (
~year: int,
~month: int,
~date: int,
~hours: int,
~minutes: int,
~seconds: int,
) => msSinceEpoch = "Date.UTC"
/**
Returns the time, in milliseconds, since UNIX epoch (January 1, 1970 00:00:00 UTC).
Be aware of using a value for year < 100, because it behaves inconsistent (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#interpretation_of_two-digit_years).
Months are 0-indexed (0 = January, 11 = December).
Values, which are out of range, will be carried over to the next bigger unit (s. example).
## Examples
```rescript
Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=0)->Console.log
// 1676911200000
Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=1000)->Console.log
// 1676911201000
Date.UTC.makeWithYMDHMSM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0, ~milliseconds=-1)->Console.log
// 1676911199999
```
*/
@val
external makeWithYMDHMSM: (
~year: int,
~month: int,
~date: int,
~hours: int,
~minutes: int,
~seconds: int,
~milliseconds: int,
) => msSinceEpoch = "Date.UTC"
}
/**
`now()`
Returns the time, in milliseconds, between UNIX epoch (January 1, 1970 00:00:00 UTC) and the current date time.
*/
@val
external now: unit => msSinceEpoch = "Date.now"
let equal: (t, t) => bool
let compare: (t, t) => Ordering.t
/**
`getTime(date)`
Returns the time, in milliseconds, between UNIX epoch (January 1, 1970 00:00:00 UTC) and the current date time.
Invalid dates will return NaN.
Dates before epoch will return negative numbers.
## Examples
```rescript
Date.fromString("2023-02-20")->Date.getTime
// 1676851200000
```
*/
@send
external getTime: t => msSinceEpoch = "getTime"
/**
`getTimezoneOffset(date)`
Returns the time in minutes between the UTC time and the locale time.
The timezone of the given date doesn't matter.
## Examples
```rescript
Date.fromString("2023-01-01")->Date.getTimezoneOffset
// -60 with local time zone = Europe/Berlin
Date.fromString("2023-06-01")->Date.getTimezoneOffset
// -120 with local time zone = Europe/Berlin
```
*/
@send
external getTimezoneOffset: t => int = "getTimezoneOffset"
/**
`getFullYear(date)`
Returns the year of a given date (according to local time).
## Examples
```rescript
Date.fromString("2023-02-20")->Date.getFullYear
// 2023
```
*/
@send
external getFullYear: t => int = "getFullYear"
/**
`getMonth(date)`
Returns the month (0-indexed) of a given date (according to local time).
## Examples
```rescript
Date.fromString("2023-01-01")->Date.getMonth
// 0
```
*/
@send
external getMonth: t => int = "getMonth"
/**
`getDate(date)`
Returns the date (day of month) of a given date (according to local time).
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.getDate
// 20
```
*/
@send
external getDate: t => int = "getDate"
/**
`getHours(date)`
Returns the hours of a given date (according to local time).
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.getHours
// 16
```
*/
@send
external getHours: t => int = "getHours"
/**
`getMinutes(date)`
Returns the minutes of a given date (according to local time).
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.getMinutes
// 40
```
*/
@send
external getMinutes: t => int = "getMinutes"
/**
`getSeconds(date)`
Returns the seconds of a given date (according to local time).
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.getSeconds
// 0
```
*/
@send
external getSeconds: t => int = "getSeconds"
/**
`getMilliseconds(date)`
Returns the milliseconds of a given date (according to local time).
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.getMilliseconds
// 0
```
*/
@send
external getMilliseconds: t => int = "getMilliseconds"
/**
`getDay(date)`
Returns the day of week of a given date (according to local time).
0 = Sunday, 1 = Monday, ... 6 = Saturday
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.getDay
// 1
```
*/
@send
external getDay: t => int = "getDay"
/**
`setFullYear(date, year)`
Sets the year of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYear(2024)
```
*/
@send
external setFullYear: (t, int) => unit = "setFullYear"
/**
`setFullYearM(date, ~year, ~month)`
Sets the year and month of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearM(~year=2024, ~month=0)
```
*/
@send
external setFullYearM: (t, ~year: int, ~month: int) => unit = "setFullYear"
/**
`setFullYearMD(date, ~year, ~month, ~date)`
Sets the year, month and date (day of month) of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearMD(~year=2024, ~month=0, ~date=1)
```
*/
@send
external setFullYearMD: (t, ~year: int, ~month: int, ~date: int) => unit = "setFullYear"
/**
`setMonth(date, month)`
Sets the month of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setMonth(0)
```
*/
@send
external setMonth: (t, int) => unit = "setMonth"
/**
`setDate(date, day)`
Sets the date (day of month) of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setDate(1)
```
*/
@send
external setDate: (t, int) => unit = "setDate"
/**
`setHours(date, hours)`
Sets the hours of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setHours(0)
```
*/
@send
external setHours: (t, int) => unit = "setHours"
/**
`setHoursM(date, ~hours, ~minutes)`
Sets the hours and minutes of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursM(~hours=0, ~minutes=0)
```
*/
@send
external setHoursM: (t, ~hours: int, ~minutes: int) => unit = "setHours"
/**
`setHoursMS(date, ~hours, ~minutes, ~seconds)`
Sets the hours, minutes and seconds of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMS(~hours=0, ~minutes=0, ~seconds=0)
```
*/
@send
external setHoursMS: (t, ~hours: int, ~minutes: int, ~seconds: int) => unit = "setHours"
/**
`setHoursMSMs(date, ~hours, ~minutes, ~seconds, ~milliseconds)`
Sets the hours, minutes, seconds and milliseconds of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMSMs(~hours=0, ~minutes=0, ~seconds=0, ~milliseconds=0)
```
*/
@send
external setHoursMSMs: (t, ~hours: int, ~minutes: int, ~seconds: int, ~milliseconds: int) => unit =
"setHours"
/**
`setMinutes(date, minutes)`
Sets the minutes of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutes(0)
```
*/
@send
external setMinutes: (t, int) => unit = "setMinutes"
/**
`setMinutesS(date, ~minutes, ~seconds)`
Sets the minutes and seconds of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesS(~minutes=0, ~seconds=0)
```
*/
@send
external setMinutesS: (t, ~minutes: int, ~seconds: int) => unit = "setMinutes"
/**
`setMinutesSMs(date, ~minutes, ~seconds, ~milliseconds)`
Sets the minutes, seconds and milliseconds of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesSMs(~minutes=0, ~seconds=0, ~milliseconds=0)
```
*/
@send
external setMinutesSMs: (t, ~minutes: int, ~seconds: int, ~milliseconds: int) => unit = "setMinutes"
/**
`setSeconds(date, seconds)`
Sets the seconds of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setSeconds(0)
```
*/
@send
external setSeconds: (t, int) => unit = "setSeconds"
/**
`setSecondsMs(date, ~seconds, ~milliseconds)`
Sets the seconds and milliseconds of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setSecondsMs(~seconds=0, ~milliseconds=0)
```
*/
@send
external setSecondsMs: (t, ~seconds: int, ~milliseconds: int) => unit = "setSeconds"
/**
`setMilliseconds(date, milliseconds)`
Sets the milliseconds of a date (according to local time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setMilliseconds(0)
```
*/
@send
external setMilliseconds: (t, int) => unit = "setMilliseconds"
/**
`getUTCFullYear(date)`
Returns the year of a given date (according to UTC time).
## Examples
```rescript
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCFullYear // 2022
```
*/
@send
external getUTCFullYear: t => int = "getUTCFullYear"
/**
`getUTCMonth(date)`
Returns the month of a given date (according to UTC time).
## Examples
```rescript
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMonth // 11
```
*/
@send
external getUTCMonth: t => int = "getUTCMonth"
/**
`getUTCDate(date)`
Returns the date (day of month) of a given date (according to UTC time).
## Examples
```rescript
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDate // 31
```
*/
@send
external getUTCDate: t => int = "getUTCDate"
/**
`getUTCHours(date)`
Returns the hours of a given date (according to UTC time).
## Examples
```rescript
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCHours // 23
```
*/
@send
external getUTCHours: t => int = "getUTCHours"
/**
`getUTCMinutes(date)`
Returns the minutes of a given date (according to UTC time).
## Examples
```rescript
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMinutes // 0
```
*/
@send
external getUTCMinutes: t => int = "getUTCMinutes"
/**
`getUTCSeconds(date)`
Returns the seconds of a given date (according to UTC time).
## Examples
```rescript
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCSeconds // 0
```
*/
@send
external getUTCSeconds: t => int = "getUTCSeconds"
/**
`getUTCMilliseconds(date)`
Returns the milliseconds of a given date (according to UTC time).
## Examples
```rescript
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMilliseconds // 0
```
*/
@send
external getUTCMilliseconds: t => int = "getUTCMilliseconds"
/**
`getUTCDay(date)`
Returns the day (day of week) of a given date (according to UTC time).
0 = Sunday, 1 = Monday, ... 6 = Saturday
## Examples
```rescript
Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDay // 6
```
*/
@send
external getUTCDay: t => int = "getUTCDay"
/**
`setUTCFullYear(date, year)`
Sets the year of a date (according to UTC time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYear(2024)
```
*/
@send
external setUTCFullYear: (t, int) => unit = "setUTCFullYear"
/**
`setUTCFullYearM(date, ~year, ~month)`
Sets the year and month of a date (according to UTC time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearM(~year=2024, ~month=0)
```
*/
@send
external setUTCFullYearM: (t, ~year: int, ~month: int) => unit = "setUTCFullYear"
/**
`setUTCFullYearMD(date, ~year, ~month, ~date)`
Sets the year, month and date (day of month) of a date (according to UTC time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearMD(~year=2024, ~month=0, ~date=1)
```
*/
@send
external setUTCFullYearMD: (t, ~year: int, ~month: int, ~date: int) => unit = "setUTCFullYear"
/**
`setUTCMonth(date, month)`
Sets the month of a date (according to UTC time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMonth(0)
```
*/
@send
external setUTCMonth: (t, int) => unit = "setUTCMonth"
/**
`setDate(date, day)`
Sets the date (day of month) of a date (according to UTC time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCDate(1)
```
*/
@send
external setUTCDate: (t, int) => unit = "setUTCDate"
/**
`setUTCHours(date, hours)`
Sets the hours of a date (according to UTC time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHours(0)
```
*/
@send
external setUTCHours: (t, int) => unit = "setUTCHours"
/**
`setHoursM(date, ~hours, ~minutes)`
Sets the hours and minutes of a date (according to UTC time).
Beware this will *mutate* the date.
## Examples
```rescript
Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursM(~hours=0, ~minutes=0)
```
*/
@send
external setUTCHoursM: (t, ~hours: int, ~minutes: int) => unit = "setUTCHours"
/**
`setUTCHoursMS(date, ~hours, ~minutes, ~seconds)`
Sets the hours, minutes and seconds of a date (according to UTC time).
Beware this will *mutate* the date.