French Republican calendar: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added syntax colouring, made p2js compatible) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 21: | Line 21: | ||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
Computes leap years using the "continuous" method: a year in the Republican calendar is a leap year if and only if the number of the <i>following</i> year is divisible by 4 but not by 100 unless also by 400. No attempt is made to deal with ill-formed or invalid input dates. |
Computes leap years using the "continuous" method: a year in the Republican calendar is a leap year if and only if the number of the <i>following</i> year is divisible by 4 but not by 100 unless also by 400. No attempt is made to deal with ill-formed or invalid input dates. |
||
< |
<syntaxhighlight lang="bbcbasic">REM >frrepcal |
||
: |
: |
||
DIM gregorian$(11) |
DIM gregorian$(11) |
||
Line 157: | Line 157: | ||
: |
: |
||
DEF FN_gre_leap(year%) |
DEF FN_gre_leap(year%) |
||
= (year% MOD 4 = 0 AND (year% MOD 100 <> 0 OR year% MOD 400 = 0))</ |
= (year% MOD 4 = 0 AND (year% MOD 100 <> 0 OR year% MOD 400 = 0))</syntaxhighlight> |
||
<b>Output for the test dates:</b> |
<b>Output for the test dates:</b> |
||
<pre>*** French Republican *** |
<pre>*** French Republican *** |
||
Line 199: | Line 199: | ||
{{trans|BBC BASIC}} |
{{trans|BBC BASIC}} |
||
Computes leap years using the "continuous" method: a year in the Republican calendar is a leap year if and only if the number of the <i>following</i> year is divisible by 4 but not by 100 unless also by 400. No attempt is made to deal with ill-formed or invalid input dates. |
Computes leap years using the "continuous" method: a year in the Republican calendar is a leap year if and only if the number of the <i>following</i> year is divisible by 4 but not by 100 unless also by 400. No attempt is made to deal with ill-formed or invalid input dates. |
||
< |
<syntaxhighlight lang="freebasic">' version 18 Pluviose 227 |
||
' compile with: fbc -s console |
' compile with: fbc -s console |
||
' retained the original comments for then BBC BASIC entry |
' retained the original comments for then BBC BASIC entry |
||
Line 385: | Line 385: | ||
Loop Until src = "" |
Loop Until src = "" |
||
End</ |
End</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>> 1 Vendemiaire 1 > 22 September 1792 > 1 Vendemiaire 1 > 23 September 1806 > 1 Vendemiaire 15 |
<pre>> 1 Vendemiaire 1 > 22 September 1792 > 1 Vendemiaire 1 > 23 September 1806 > 1 Vendemiaire 15 |
||
Line 417: | Line 417: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// French Republican Calander: Nigel Galloway. April 16th., 2021 |
// French Republican Calander: Nigel Galloway. April 16th., 2021 |
||
let firstDay=System.DateTime.Parse("22/9/1792") |
let firstDay=System.DateTime.Parse("22/9/1792") |
||
Line 462: | Line 462: | ||
let n,g,l=Greg2FRC(System.DateTime(1803,9,23)) in printfn "%d %s %d -> %d %A %d" 23 "September" 1803 n g l |
let n,g,l=Greg2FRC(System.DateTime(1803,9,23)) in printfn "%d %s %d -> %d %A %d" 23 "September" 1803 n g l |
||
let n,g,l=Greg2FRC(System.DateTime(1805,12,31)) in printfn "%d %s %d -> %d %A %d" 31 "December" 1805 n g l |
let n,g,l=Greg2FRC(System.DateTime(1805,12,31)) in printfn "%d %s %d -> %d %A %d" 31 "December" 1805 n g l |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 477: | Line 477: | ||
{{trans|BBC Basic}} |
{{trans|BBC Basic}} |
||
A rather literal port, just for reference. Far from idiomatic Go. |
A rather literal port, just for reference. Far from idiomatic Go. |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 639: | Line 639: | ||
func greLeap(year int) bool { |
func greLeap(year int) bool { |
||
return year%4 == 0 && (year%100 != 0 || year%400 == 0) |
return year%4 == 0 && (year%100 != 0 || year%400 == 0) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 678: | Line 678: | ||
A start anyway. Computations extracted to a package, a type defined for French Republican Dates, time package from standard library used. Ignores invalid input rather than panicking. |
A start anyway. Computations extracted to a package, a type defined for French Republican Dates, time package from standard library used. Ignores invalid input rather than panicking. |
||
< |
<syntaxhighlight lang="go">package frc |
||
import ( |
import ( |
||
Line 835: | Line 835: | ||
func greLeap(year int) bool { |
func greLeap(year int) bool { |
||
return year%4 == 0 && (year%100 != 0 || year%400 == 0) |
return year%4 == 0 && (year%100 != 0 || year%400 == 0) |
||
}</ |
}</syntaxhighlight> |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 874: | Line 874: | ||
} |
} |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
To stay within historical dates, will throw a domain error if the French Republican date is outside the interval the calendar was actually used. |
To stay within historical dates, will throw a domain error if the French Republican date is outside the interval the calendar was actually used. |
||
< |
<syntaxhighlight lang="julia">using Dates |
||
const GC_FORMAT = DateFormat("d U y") |
const GC_FORMAT = DateFormat("d U y") |
||
Line 962: | Line 962: | ||
testrepublicancalendar() |
testrepublicancalendar() |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
French Republican to Gregorian |
French Republican to Gregorian |
||
Line 979: | Line 979: | ||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
< |
<syntaxhighlight lang="scala">// version 1.1.4-3 |
||
import java.time.format.DateTimeFormatter |
import java.time.format.DateTimeFormatter |
||
Line 1,092: | Line 1,092: | ||
println("${frcDate.padEnd(25)} => $lds") |
println("${frcDate.padEnd(25)} => $lds") |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,121: | Line 1,121: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
As was done in Julia version, we have limited the date range to historical dates only. |
As was done in Julia version, we have limited the date range to historical dates only. |
||
<syntaxhighlight lang="nim"> |
|||
<lang Nim> |
|||
import strformat, strscans, strutils, times |
import strformat, strscans, strutils, times |
||
Line 1,258: | Line 1,258: | ||
echo "From gregorian dates to French republican dates:" |
echo "From gregorian dates to French republican dates:" |
||
for gdate in GregorianDates: |
for gdate in GregorianDates: |
||
echo &"{gdate:>24} → {gdate.toRepublican()}"</ |
echo &"{gdate:>24} → {gdate.toRepublican()}"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,276: | Line 1,276: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">use feature 'state'; |
||
use DateTime; |
use DateTime; |
||
my @month_names = qw{ |
my @month_names = qw{ |
||
Line 1,400: | Line 1,400: | ||
2016-09-22 1 Vendémiaire 225 |
2016-09-22 1 Vendémiaire 225 |
||
2017-09-22 1 Vendémiaire 226 |
2017-09-22 1 Vendémiaire 226 |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{Out}} |
{{Out}} |
||
<pre>All tests successful.</pre> |
<pre>All tests successful.</pre> |
||
Line 1,406: | Line 1,406: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">constant</span> <span style="color: #000000;">gregorians</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"January"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"February"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"March"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"April"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"May"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"June"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"July"</span><span style="color: #0000FF;">,</span> |
<span style="color: #008080;">constant</span> <span style="color: #000000;">gregorians</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"January"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"February"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"March"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"April"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"May"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"June"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"July"</span><span style="color: #0000FF;">,</span> |
||
Line 1,581: | Line 1,581: | ||
<span style="color: #008080;">if</span> <span style="color: #000000;">gre_to_day</span><span style="color: #0000FF;">(</span><span style="color: #000000;">day_to_gre</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">))!=</span><span style="color: #000000;">i</span> <span style="color: #008080;">then</span> <span style="color: #0000FF;">?</span><span style="color: #000000;">9</span><span style="color: #0000FF;">/</span><span style="color: #000000;">0</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
<span style="color: #008080;">if</span> <span style="color: #000000;">gre_to_day</span><span style="color: #0000FF;">(</span><span style="color: #000000;">day_to_gre</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">))!=</span><span style="color: #000000;">i</span> <span style="color: #008080;">then</span> <span style="color: #0000FF;">?</span><span style="color: #000000;">9</span><span style="color: #0000FF;">/</span><span style="color: #000000;">0</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span> |
||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,629: | Line 1,629: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
<lang |
<syntaxhighlight lang="raku" line>use v6; |
||
constant @month_names = < |
constant @month_names = < |
||
Vendémiaire Brumaire Frimaire Nivôse Pluviôse Ventôse |
Vendémiaire Brumaire Frimaire Nivôse Pluviôse Ventôse |
||
Line 1,743: | Line 1,743: | ||
or Republican_to_Gregorian(Gregorian_to_Republican($g)) != $g; |
or Republican_to_Gregorian(Gregorian_to_Republican($g)) != $g; |
||
} |
} |
||
say 'All tests successful.';</ |
say 'All tests successful.';</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>All tests successful.</pre> |
<pre>All tests successful.</pre> |
||
Line 1,749: | Line 1,749: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
{{trans|Perl}} |
{{trans|Perl}} |
||
< |
<syntaxhighlight lang="ruby">require('DateTime') |
||
var month_names = %w( |
var month_names = %w( |
||
Line 1,896: | Line 1,896: | ||
2015-09-23 1 Vendémiaire 224 |
2015-09-23 1 Vendémiaire 224 |
||
2016-09-22 1 Vendémiaire 225 |
2016-09-22 1 Vendémiaire 225 |
||
2017-09-22 1 Vendémiaire 226</ |
2017-09-22 1 Vendémiaire 226</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,907: | Line 1,907: | ||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/date" for Date |
||
import "/seq" for Lst |
import "/seq" for Lst |
||
import "/fmt" for Fmt |
import "/fmt" for Fmt |
||
Line 2,021: | Line 2,021: | ||
var lds = thisDate.toLocalDate.format(fmt) |
var lds = thisDate.toLocalDate.format(fmt) |
||
Fmt.print("$-25s => $s", frcDate, lds) |
Fmt.print("$-25s => $s", frcDate, lds) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |