French Republican calendar: Difference between revisions

m
m (→‎{{header|Phix}}: added syntax colouring, made p2js compatible)
m (→‎{{header|Wren}}: Minor tidy)
 
(One intermediate revision by one other user not shown)
Line 21:
=={{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.
<langsyntaxhighlight lang="bbcbasic">REM >frrepcal
:
DIM gregorian$(11)
Line 157:
:
DEF FN_gre_leap(year%)
= (year% MOD 4 = 0 AND (year% MOD 100 <> 0 OR year% MOD 400 = 0))</langsyntaxhighlight>
<b>Output for the test dates:</b>
<pre>*** French Republican ***
Line 199:
{{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.
<langsyntaxhighlight lang="freebasic">' version 18 Pluviose 227
' compile with: fbc -s console
' retained the original comments for then BBC BASIC entry
Line 385:
Loop Until src = ""
 
End</langsyntaxhighlight>
{{out}}
<pre>> 1 Vendemiaire 1 > 22 September 1792 > 1 Vendemiaire 1 > 23 September 1806 > 1 Vendemiaire 15
Line 417:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// French Republican Calander: Nigel Galloway. April 16th., 2021
let firstDay=System.DateTime.Parse("22/9/1792")
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(1805,12,31)) in printfn "%d %s %d -> %d %A %d" 31 "December" 1805 n g l
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 477:
{{trans|BBC Basic}}
A rather literal port, just for reference. Far from idiomatic Go.
<langsyntaxhighlight lang="go">package main
 
import (
Line 639:
func greLeap(year int) bool {
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
}</langsyntaxhighlight>
{{out}}
<pre>
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.
<langsyntaxhighlight lang="go">package frc
 
import (
Line 835:
func greLeap(year int) bool {
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
}</langsyntaxhighlight>
<langsyntaxhighlight lang="go">package main
 
import (
Line 874:
}
}
}</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="julia">using Dates
 
const GC_FORMAT = DateFormat("d U y")
Line 962:
 
testrepublicancalendar()
</langsyntaxhighlight>{{out}}
<pre>
French Republican to Gregorian
Line 979:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.4-3
 
import java.time.format.DateTimeFormatter
Line 1,092:
println("${frcDate.padEnd(25)} => $lds")
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,121:
=={{header|Nim}}==
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
 
Line 1,258:
echo "From gregorian dates to French republican dates:"
for gdate in GregorianDates:
echo &"{gdate:>24} → {gdate.toRepublican()}"</langsyntaxhighlight>
 
{{out}}
Line 1,276:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use feature 'state';
use DateTime;
my @month_names = qw{
Line 1,400:
2016-09-22 1 Vendémiaire 225
2017-09-22 1 Vendémiaire 226
</syntaxhighlight>
</lang>
{{Out}}
<pre>All tests successful.</pre>
Line 1,406:
=={{header|Phix}}==
 
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
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;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,629:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>use v6;
constant @month_names = <
Vendémiaire Brumaire Frimaire Nivôse Pluviôse Ventôse
Line 1,743:
or Republican_to_Gregorian(Gregorian_to_Republican($g)) != $g;
}
say 'All tests successful.';</langsyntaxhighlight>
{{Out}}
<pre>All tests successful.</pre>
Line 1,749:
=={{header|Sidef}}==
{{trans|Perl}}
<langsyntaxhighlight lang="ruby">require('DateTime')
 
var month_names = %w(
Line 1,896:
2015-09-23 1 Vendémiaire 224
2016-09-22 1 Vendémiaire 225
2017-09-22 1 Vendémiaire 226</langsyntaxhighlight>
{{out}}
<pre>
Line 1,907:
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./date" for Date
import "./seq" for Lst
import "./fmt" for Fmt
 
class FrenchRCDate {
Line 2,021:
var lds = thisDate.toLocalDate.format(fmt)
Fmt.print("$-25s => $s", frcDate, lds)
}</langsyntaxhighlight>
 
{{out}}
9,476

edits