French Republican calendar: Difference between revisions
Content deleted Content added
added FreeBASIC |
|||
(16 intermediate revisions by 7 users not shown) | |||
Line 1:
{{
Write a program to convert dates between the [[wp:Gregorian calendar|Gregorian calendar]] and the [[wp:French Republican Calendar|French Republican calendar]].
Line 18:
• 10 Nivôse 14 = 31 December 1805
=={{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.
<
:
DIM gregorian$(11)
Line 148 ⟶ 146:
m% = 1
y% += 1
IF FN_rep_leap(y%) THEN sansculottides% = 6 ELSE sansculottides% = 5
ENDIF
ENDIF
Line 158 ⟶ 157:
:
DEF FN_gre_leap(year%)
= (year% MOD 4 = 0 AND (year% MOD 100 <> 0 OR year% MOD 400 = 0))</
<b>Output for the test dates:</b>
<pre>*** French Republican ***
Line 196 ⟶ 195:
> 19 September 2016
Fete du travail 224</pre>
=={{header|FreeBASIC}}==
{{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.
<syntaxhighlight lang="freebasic">' version 18 Pluviose 227
' compile with: fbc -s console
' retained the original comments for then BBC BASIC entry
Line 383 ⟶ 385:
Loop Until src = ""
End</
{{out}}
<pre>> 1 Vendemiaire 1 > 22 September 1792 > 1 Vendemiaire 1 > 23 September 1806 > 1 Vendemiaire 15
Line 414 ⟶ 416:
1 Vendemiaire 14 23 September 1805</pre>
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// French Republican Calander: Nigel Galloway. April 16th., 2021
let firstDay=System.DateTime.Parse("22/9/1792")
type monthsFRC= Vendemiaire = 0
|Brumaire = 30
|Frimaire = 60
|Nivose = 90
|Pluviose = 120
|Ventose = 150
|Germinal = 180
|Floral = 210
|Prairial = 240
|Messidor = 270
|Thermidor = 300
|Fructidor = 330
|Virtue = 360
|Talent = 361
|Labour = 362
|Opinion = 363
|Honours = 364
|Revolution = 365
type months= January = 1
|February = 2
|March = 3
|April = 4
|May = 5
|June = 6
|July = 7
|August = 8
|September = 9
|October = 10
|November = 11
|December = 12
let frc2Greg n (g:monthsFRC) l=firstDay+System.TimeSpan.FromDays(float((l-1)*365+l/4+(int g)+n-1))
let rec fG n g=let i=match g with 3 |7 |11->366 |_->365 in if n<i then (n,g) else fG(n-i)(g+1)
let Greg2FRC n=let n,g=fG((n-firstDay).Days) 1
match n/30,n%30 with (12,n)->(1,enum<monthsFRC>(360+n),g) |(n,l)->(l+1,enum<monthsFRC>(n*30),g)
let n=(frc2Greg 1 monthsFRC.Vendemiaire 1) in printfn "%d %s %d -> %d %A %d" 1 "Vendemiaire" 1 n.Day (enum<months> n.Month) n.Year
let n=(frc2Greg 27 monthsFRC.Messidor 7) in printfn "%d %s %d -> %d %A %d" 27 "Messidor" 7 n.Day (enum<months> n.Month) n.Year
let n=(frc2Greg 1 monthsFRC.Revolution 11) in printfn "%d %s %d -> %d %A %d" 1 "Revolution" 11 n.Day (enum<months> n.Month) n.Year
let n=(frc2Greg 10 monthsFRC.Nivose 14) in printfn "%d %s %d -> %d %A %d" 10 "Nivose" 14 n.Day (enum<months> n.Month) n.Year
let n,g,l=Greg2FRC(System.DateTime(1792,9,22)) in printfn "%d %s %d -> %d %A %d" 22 "September" 1792 n g l
let n,g,l=Greg2FRC(System.DateTime(1799,7,15)) in printfn "%d %s %d -> %d %A %d" 15 "July" 1799 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
</syntaxhighlight>
{{out}}
<pre>
1 Vendemiaire 1 -> 22 September 1792
27 Messidor 7 -> 15 July 1799
1 Revolution 11 -> 23 September 1803
10 Nivose 14 -> 31 December 1805
22 September 1792 -> 1 Vendemiaire 1
15 July 1799 -> 27 Messidor 7
23 September 1803 -> 1 Revolution 11
31 December 1805 -> 10 Nivose 14
</pre>
=={{header|Go}}==
{{trans|BBC Basic}}
A rather literal port, just for reference. Far from idiomatic Go.
<
import (
Line 579 ⟶ 639:
func greLeap(year int) bool {
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
}</
{{out}}
<pre>
Line 618 ⟶ 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.
<
import (
Line 775 ⟶ 835:
func greLeap(year int) bool {
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
}</
<
import (
Line 814 ⟶ 874:
}
}
}</
=={{header|jq}}==
'''Adapted from [[#Wren|Wren]]'''
'''Works with jq, the C implementation of jq'''
'''Works with gojq, the Go implementation of jq'''
This entry uses the [[:Category:Jq/Date.jq | "Date" module]].
Note that `assertEq/2` as defined below is used to check that the Gregorian dates survive the round-trip via
conversion to French Republican Calendar dates.
<syntaxhighlight lang="jq">
include "Date" {search: "."};
### Generic functions
def assertEq($p;$q):
if $p == $q
then .
else debug("assertion violation: \($p) != \($q)") as $debug | .
end;
def lpad($len): tostring | ($len - length) as $l | (" " * $l) + .;
def trim: sub("^ *";"") | sub(" *$";"");
# Input: string such as "12 Mar 2012"
# Output: Date
def parseDayMonthYear:
def months:
{Jan:1, Feb:2, Mar:3, Apr: 4, May: 5, Jun: 6,
Jul:7, Aug:8, Sep:9, Oct:10, Nov:11, Dec:12};
capture("(?<day>[0-9]+) *(?<month>[A-Za-z]+) *(?<year>[0-9]+)")
| .month |= months[ .[:3] ]
| map_values(tonumber)
| {year, month, day};
### French Republican Calendar (FRC)
def introductionDate: Date(1792; 9; 22);
# Use the 'continuous method' for years after 1805
def isLeapYearFRC:
(. + 1)
| (. % 4 == 0) and ((. % 100 != 0) or (. % 400 == 0));
# If the numbers $year, $month, and $day specify a valid date
# in the French Republican Calendar, then emit {$year, $month, $day};
# otherwise generate an informative error message.
def FrenchRCDate($year; $month; $day):
def err(msg): "Invalid date (\(msg)): FrenchRCDate(\($year); \($month); \($day))" | error;
if ($year <= 0 or $month < 1 or $month > 13) then err(if $year <= 0 then "year" else "month" end) end
| if $month < 13
then if $day < 1 or $day > 30 then err("day") end
else ($year | isLeapYearFRC) as $leap
| if $leap and ($day < 1 or $day > 6) then err("invalid day in leap year") end
| if ($leap|not) and ($day < 1 or $day > 5) then err("invalid day in non-leap year") end
end
| {$year, $month, $day};
# for convenience we treat 'Sansculottide' as an extra month with 5 or 6 days
def months:
["Vendémiaire", "Brumaire", "Frimaire", "Nivôse", "Pluviôse", "Ventôse", "Germinal",
"Floréal", "Prairial", "Messidor", "Thermidor", "Fructidor", "Sansculottide"] ;
def intercal:
["Fête de la vertu", "Fête du génie", "Fête du travail",
"Fête de l'opinion", "Fête des récompenses", "Fête de la Révolution"];
# Input: a string specifying a FRC date
def parse:
. as $frcDate
| (trim|split(" ")) as $splits
| if $splits|length == 3
then (months | index($splits[1]) + 1) as $month
| if $month < 1 or $month > 13 then "Invalid month." | error end
| ($splits[2]|tonumber) as $year
| if $year < 1 then "Invalid year." | error end
| (if ($month < 13) then 30 elif $year|isLeapYearFRC then 6 else 5 end) as $monthLength
| ($splits[0] | tonumber) as $day
| if $day < 1 or $day > $monthLength then "Invalid day." | error end
| FrenchRCDate($year; $month; $day)
elif ($splits|length | IN(4,5))
then $splits[-1] as $yearStr
| ($yearStr|tonumber) as $year
| if $year < 1 then "Invalid year." | error end
| ($frcDate | trim[0: -($yearStr|length + 1)] ) as $scDay
| (intercal | index($scDay) + 1) as $day
| (if $year | isLeapYearFRC then 6 else 5 end) as $maxDay
| if $day < 1 or $day > $maxDay then "Invalid day." | error end
| FrenchRCDate($year; 13; $day)
else "Invalid French Republican date." | error
end
;
# Input: Date (Gregorian)
# Output:
def fromLocalDate:
# $start and $finish should be two Date objects
def daysFrom($start; $finish):
($finish|daysBeforeDate) - ($start|daysBeforeDate);
(daysFrom(introductionDate; .) + 1) as $daysDiff
| if ($daysDiff <= 0) then "Date can't be before 22 September 1792." | error end
| {year: 1, startDay: 1}
| until(.done;
(.startDay + (if .year|isLeapYearFRC then 365 else 364 end)) as $endDay
| if ($daysDiff >= .startDay and $daysDiff <= $endDay) then .done = true
else .year += 1
| .startDay = $endDay + 1
end )
| ($daysDiff - .startDay) as $remDays
| (($remDays / 30)|floor) as $month
| ($remDays - $month * 30) as $day
| FrenchRCDate(.year; $month + 1; $day + 1)
;
# Input: an FRC Date
def toString:
if .month < 13 then "\(.day) \(months[.month - 1]) \(.year)"
else "\(intercal[.day - 1]) \(.year)"
end;
# Input: an FRC Date
def toLocalDate:
(reduce range(1; .year) as $i (0; . + (if $i|isLeapYearFRC then 366 else 365 end))) as $sumDays
| ((.month - 1) * 30 + .day - 1) as $dayInYear
| introductionDate | addDays($sumDays + $dayInYear) ;
### Examples
def dates: [
"22 September 1792", "20 May 1795", "15 July 1799", "23 September 1803",
"31 December 1805", "18 March 1871", "25 August 1944", "19 September 2016",
"22 September 2017", "28 September 2017"
];
def task:
def format:
"\(.day) \(monthNames[.month]) \(.year)";
dates as $dates
| reduce range(0; $dates|length) as $i ({};
.date = $dates[$i]
| .thisDate = (.date|parseDayMonthYear)
| .frcd = (.thisDate|fromLocalDate)
| .frcDates[$i] = (.frcd|toString)
| .emit += "\(.date|lpad(26)) => \(.frcDates[$i])\n")
| .emit,
# now process the other way around
range(0; $dates|length) as $i
| .frcDates[$i] as $frcDate
| ($frcDate|parse|toLocalDate|format) as $lds
| assertEq($dates[$i]; $lds)
| "\($frcDate|lpad(26)) => \($lds)"
;
task
</syntaxhighlight>
{{output}}
<pre>
22 September 1792 => 1 Vendémiaire 1
20 May 1795 => 1 Prairial 3
15 July 1799 => 27 Messidor 7
23 September 1803 => Fête de la Révolution 11
31 December 1805 => 10 Nivôse 14
18 March 1871 => 27 Ventôse 79
25 August 1944 => 7 Fructidor 152
19 September 2016 => Fête du travail 224
22 September 2017 => 1 Vendémiaire 226
28 September 2017 => 7 Vendémiaire 226
1 Vendémiaire 1 => 22 September 1792
1 Prairial 3 => 20 May 1795
27 Messidor 7 => 15 July 1799
Fête de la Révolution 11 => 23 September 1803
10 Nivôse 14 => 31 December 1805
27 Ventôse 79 => 18 March 1871
7 Fructidor 152 => 25 August 1944
Fête du travail 224 => 19 September 2016
1 Vendémiaire 226 => 22 September 2017
7 Vendémiaire 226 => 28 September 2017
</pre>
=={{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.
<syntaxhighlight lang="julia">using Dates
const GC_FORMAT = DateFormat("d U y")
const RC_FIRST_DAY = Date(1792, 9, 22)
const MAX_RC_DATE = Date(1805, 12, 31)
const RC_MONTHS = [
"Vendémiaire", "Brumaire", "Frimaire", "Nivôse", "Pluviôse", "Ventôse",
"Germinal", "Floréal", "Prairial", "Messidor", "Thermidor", "Fructidor"
]
const RC_DAYS_IN_MONTH = 30
const RC_SANSCULOTTIDES = [
"Fête de la vertu", "Fête du génie", "Fête du travail",
"Fête de l'opinion", "Fête des récompenses", "Fête de la Révolution"
]
additionaldaysforyear(yr) = yr > 11 ? 3 : yr > 7 ? 2 : yr > 3 ? 1 : 0
additionaldaysformonth(mo) = 30 * (mo - 1)
daysforFete(s) = findfirst(x -> x == s, RC_SANSCULOTTIDES) + 359
function togregorian(rc::String)
yearstring, firstpart = reverse.(split(reverse(strip(rc)), r"\s+", limit=2))
rcyear = parse(Int, yearstring)
pastyeardays = (rcyear - 1) * 365 + additionaldaysforyear(rcyear)
if isnumeric(firstpart[1])
daystring, monthstring = split(firstpart, r"\s+", limit=2)
nmonth = findfirst(x -> x == monthstring, RC_MONTHS)
pastmonthdays = 30 * (nmonth - 1)
furtherdays = parse(Int, daystring) + pastmonthdays + pastyeardays - 1
else
furtherdays = daysforFete(firstpart) + pastyeardays
end
gregorian = RC_FIRST_DAY + Day(furtherdays)
if furtherdays < 0 || gregorian > MAX_RC_DATE
throw(DomainError("French Republican Calendar date out of range"))
end
return Day(gregorian).value, monthname(Month(gregorian).value), Year(gregorian).value
end
function torepublican(gc::String)
date = Date(DateTime(gc, GC_FORMAT))
if date < RC_FIRST_DAY || date > MAX_RC_DATE
throw(DomainError("French Republican Calendar date out of range"))
end
rcyear, rcdays = divrem(((date - RC_FIRST_DAY).value + 366), 365)
rcdays -= additionaldaysforyear(rcyear)
if rcdays < 1
rcyear -= 1
rcdays += 366
end
if rcdays < 361
nmonth, rcday = divrem(rcdays, 30)
return rcday, RC_MONTHS[nmonth + 1], rcyear
else
return RC_SANSCULOTTIDES[rcdays - 360], rcyear
end
end
const republican = [
"1 Vendémiaire 1", "1 Prairial 3", "27 Messidor 7",
"Fête de la Révolution 11", "10 Nivôse 14"
]
const gregorian = [
"22 September 1792", "20 May 1795", "15 July 1799",
"23 September 1803", "31 December 1805"
]
function testrepublicancalendar()
println("French Republican to Gregorian")
for s in republican
println(lpad(s, 24), " => ", togregorian(s))
end
println("Gregorian to French Republican")
for s in gregorian
println(lpad(s, 24), " => ", torepublican(s))
end
end
testrepublicancalendar()
</syntaxhighlight>{{out}}
<pre>
French Republican to Gregorian
1 Vendémiaire 1 => (22, "September", 1792)
1 Prairial 3 => (20, "May", 1795)
27 Messidor 7 => (15, "July", 1799)
Fête de la Révolution 11 => (23, "September", 1803)
10 Nivôse 14 => (31, "December", 1805)
Gregorian to French Republican
22 September 1792 => (1, "Vendémiaire", 1)
20 May 1795 => (1, "Prairial", 3)
15 July 1799 => (27, "Messidor", 7)
23 September 1803 => ("Fête de la Révolution", 11)
31 December 1805 => (10, "Nivôse", 14)
</pre>
=={{header|Kotlin}}==
<
import java.time.format.DateTimeFormatter
Line 930 ⟶ 1,280:
println("${frcDate.padEnd(25)} => $lds")
}
}</
{{out}}
Line 956 ⟶ 1,306:
7 Vendémiaire 226 => 28 September 2017
</pre>
=={{header|Nim}}==
As was done in Julia version, we have limited the date range to historical dates only.
<syntaxhighlight lang="nim">
import strformat, strscans, strutils, times
const
RcMonths = ["Vendémiaire", "Brumaire", "Frimaire", "Nivôse", "Pluviôse", "Ventôse",
"Germinal", "Floréal", "Prairial", "Messidor", "Thermidor", "Fructidor"]
SansCulottides = ["Fête de la vertu", "Fête du génie", "Fête du travail",
"Fête de l’opinion", "Fête des récompenses", "Fête de la Révolution"]
let
# First and last dates of republican calendar expressed in gregorian calendar.
FirstRcDate = initDateTime(22, mSep, 1792, 0, 0, 0)
LastRcDate = initDateTime(31, mDec, 1805, 0, 0, 0)
type
# French republican date representation.
RcDayRange = 1..30
RcMonthRange = 1..13
RcYearRange = 1..14
RepublicanDate = tuple[year: RcYearRange, month: RcMonthRange, day: RcDayRange]
# Last dates of republican calendar expressed in republican calendar.
const RcLastDate: RepublicanDate = (RcYearRange(14), RcMonthRange(4), RcDayRange(10))
proc notnum(input: string; str: var string; start: int): int =
# Parsing procedure to extract non numerical part of a date.
var i = start
while i <= input.high:
if input[i] in '0'..'9': break
str.add input[i]
inc i
if str.len == 0 or str[^1] != ' ': return -1 # Not terminated by a space.
str.setLen(str.len - 1) # Back before the space.
result = str.len
proc parseRepublicanDate(rdate: string): RepublicanDate =
## Parse a French republican date and return its representation.
let date = rdate.strip()
var day, month, year: int
var monthString, dayString: string
if date.scanf("$i $+ $i", day, monthString, year):
# Normal day.
if day notin 1..30:
raise newException(ValueError, "wrong day number: $1.".format(day))
month = RcMonths.find(monthString) + 1
if month == 0:
raise newException(ValueError, "unknown French republican month: $1." % monthString)
elif date.scanf("${notnum} $i", dayString, year):
# Sans-culottide day (also known as “jour complémentaire”).
month = 13 # Value used for sans-culottide days.
day = SansCulottides.find(dayString) + 1
if day == 0:
raise newException(ValueError, "wrong “sans-culottide” day: « $1 »." % dayString)
if day == 6 and year mod 4 != 3:
raise newException(ValueError, "republican year $1 is not a leap year".format(year))
else:
raise newException(ValueError, "invalid French republican date: « $1 »." % date)
result = (RcYearRange(year), RcMonthRange(month), RcDayRange(day))
if result > RcLastDate:
raise newException(ValueError, "republican date out of range: « $1 »." % date)
proc `$`(date: RepublicanDate): string =
## Return the string representation of a French republican date.
if date.month != 13:
# Normal day.
result = "$1 $2 $3".format(date.day, RcMonths[date.month - 1], date.year)
else:
# Supplementary day.
result = "$1 $2".format(SansCulottides[date.day - 1], date.year)
proc toGregorian(rdate: RepublicanDate): DateTime =
## Convert a republican date tuple to a gregorian date (DateTime object).
let day = (rdate.day - 1) + (rdate.month - 1) * 30 + (rdate.year - 1) * 365 + rdate.year div 4
result = FirstRcDate + initTimeInterval(days = day)
proc toGregorian(rdate: string): string =
## Convert a republican date string to a gregorian date string.
let date = rdate.parseRepublicanDate()
result = date.toGregorian().format("dd MMMM yyyy")
proc toRepublican(gdate: DateTime): RepublicanDate =
## Convert a gregorian date (DateTime object) to a republican date tuple.
if gdate notin FirstRcDate..LastRcDate:
raise newException(ValueError, "impossible conversion to republican date.")
let d = gdate - FirstRcDate
# Add a dummy year before year 1 in order to use a four years period.
let dayNumber = d.inDays + 365
let periodNum = dayNumber div 1461
let dayInPeriod = dayNumber mod 1461
# Compute year and day in year.
let yearInPeriod = min(dayInPeriod div 365, 3)
result.year = periodNum * 4 + yearInPeriod
let dayInYear = dayInPeriod - yearInPeriod * 365
# Compute month and day.
result.month = dayInYear div 30 + 1
result.day = dayInYear mod 30 + 1
proc toRepublican(gdate: string): string =
## Convert a gregorian date string to a republican date string.
let date = gdate.parse("d MMMM yyyy")
result = $(date.toRepublican())
when isMainModule:
const
RepublicanDates = ["1 Vendémiaire 1", "1 Prairial 3", "27 Messidor 7",
"Fête de la Révolution 11", "10 Nivôse 14"]
GregorianDates = ["22 September 1792", "20 May 1795", "15 July 1799",
"23 September 1803", "31 December 1805"]
echo "From French republican dates to gregorian dates:"
for rdate in RepublicanDates:
echo &"{rdate:>24} → {rdate.toGregorian()}"
echo()
echo "From gregorian dates to French republican dates:"
for gdate in GregorianDates:
echo &"{gdate:>24} → {gdate.toRepublican()}"</syntaxhighlight>
{{out}}
<pre>From French republican dates to gregorian dates:
1 Vendémiaire 1 → 22 September 1792
1 Prairial 3 → 20 May 1795
27 Messidor 7 → 15 July 1799
Fête de la Révolution 11 → 23 September 1803
10 Nivôse 14 → 31 December 1805
From gregorian dates to French republican dates:
22 September 1792 → 1 Vendémiaire 1
20 May 1795 → 1 Prairial 3
15 July 1799 → 27 Messidor 7
23 September 1803 → Fête de la Révolution 11
31 December 1805 → 10 Nivôse 14</pre>
=={{header|Perl}}==
<
use DateTime;
my @month_names = qw{
Line 1,082 ⟶ 1,588:
2016-09-22 1 Vendémiaire 225
2017-09-22 1 Vendémiaire 226
</syntaxhighlight>
{{Out}}
<pre>All tests successful.</pre>
=={{header|
<!--<syntaxhighlight lang="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>
<span style="color: #008000;">"August"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"September"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"October"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"November"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"December"</span><span style="color: #0000FF;">},</span>
<span style="color: #000000;">gregorian</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">31</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">28</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">31</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">30</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">31</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">30</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">31</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">31</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">30</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">31</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">30</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">31</span><span style="color: #0000FF;">},</span>
<span style="color: #000000;">republicans</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Vendémiaire"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Brumaire"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Frimaire"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Nivôse"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Pluviôse"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"Ventôse"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Germinal"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Floréal"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Prairial"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Messidor"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"Thermidor"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Fructidor"</span><span style="color: #0000FF;">},</span>
<span style="color: #000000;">sansculottides</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"Fête de la vertu"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Fête du génie"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Fête du travail"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"Fête de l'opinion"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Fête des récompenses"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"Fête de la Révolution"</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">rep_leap</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">year</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">year</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)==</span><span style="color: #000000;">0</span> <span style="color: #008080;">and</span> <span style="color: #0000FF;">(</span><span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">year</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">or</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">year</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">400</span><span style="color: #0000FF;">)==</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">rep_to_day</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">dmy</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">d</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">m</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dmy</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">m</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">13</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">m</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">d</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">30</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">rep_leap</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">d</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">365</span><span style="color: #0000FF;">*(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">((</span><span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">-</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">((</span><span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">((</span><span style="color: #000000;">y</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">400</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">30</span><span style="color: #0000FF;">*(</span><span style="color: #000000;">m</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">d</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">gre_leap</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">year</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">year</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)==</span><span style="color: #000000;">0</span> <span style="color: #008080;">and</span> <span style="color: #0000FF;">(</span><span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">year</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">or</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">year</span><span style="color: #0000FF;">,</span><span style="color: #000000;">400</span><span style="color: #0000FF;">)==</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">gre_to_day</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">dmy</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">d</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">m</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">y</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">dmy</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">m</span> <span style="color: #0000FF;"><</span> <span style="color: #000000;">3</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">m</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">12</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">*</span><span style="color: #000000;">365.25</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">-</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">/</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">/</span><span style="color: #000000;">400</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">+</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">30.6</span><span style="color: #0000FF;">*(</span><span style="color: #000000;">m</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">))</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">d</span> <span style="color: #0000FF;">-</span> <span style="color: #000000;">654842</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">day_to_rep</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">day</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">y</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">((</span><span style="color: #000000;">day</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">365.25</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #000000;">rep_leap</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">d</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">day</span> <span style="color: #0000FF;">-</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">*</span><span style="color: #000000;">365.25</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">365</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">/</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">-</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">/</span><span style="color: #000000;">400</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">m</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">sansculottide</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">+</span><span style="color: #000000;">rep_leap</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">></span><span style="color: #000000;">30</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">d</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">30</span>
<span style="color: #000000;">m</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">m</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">13</span> <span style="color: #008080;">then</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">d</span> <span style="color: #0000FF;">></span> <span style="color: #000000;">sansculottide</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">d</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">sansculottide</span>
<span style="color: #000000;">m</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">sansculottide</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">rep_leap</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">return</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">d</span><span style="color: #0000FF;">,</span><span style="color: #000000;">m</span><span style="color: #0000FF;">,</span><span style="color: #000000;">y</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">day_to_gre</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">day</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">y</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">day</span><span style="color: #0000FF;">/</span><span style="color: #000000;">365.25</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">d</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">day</span> <span style="color: #0000FF;">-</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">*</span><span style="color: #000000;">365.25</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">21</span><span style="color: #0000FF;">,</span>
<span style="color: #000000;">m</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">9</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1792</span>
<span style="color: #000000;">d</span> <span style="color: #0000FF;">+=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">/</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">-</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">/</span><span style="color: #000000;">400</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">-</span> <span style="color: #000000;">13</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">gregoriam</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">deep_copy</span><span style="color: #0000FF;">(</span><span style="color: #000000;">gregorian</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (modifiable copy)</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">></span><span style="color: #000000;">gregoriam</span><span style="color: #0000FF;">[</span><span style="color: #000000;">m</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">d</span> <span style="color: #0000FF;">-=</span> <span style="color: #000000;">gregoriam</span><span style="color: #0000FF;">[</span><span style="color: #000000;">m</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">m</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">m</span> <span style="color: #0000FF;">==</span> <span style="color: #000000;">13</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">m</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">y</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #000000;">gregoriam</span><span style="color: #0000FF;">[</span><span style="color: #000000;">2</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">28</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">gre_leap</span><span style="color: #0000FF;">(</span><span style="color: #000000;">y</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">return</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">d</span><span style="color: #0000FF;">,</span><span style="color: #000000;">m</span><span style="color: #0000FF;">,</span><span style="color: #000000;">y</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">greg_to_frep</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">greg</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">{</span><span style="color: #004080;">integer</span> <span style="color: #000000;">day</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">string</span> <span style="color: #000000;">months</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">year</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">scanf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">greg</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d %s %d"</span><span style="color: #0000FF;">)[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">month</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">months</span><span style="color: #0000FF;">,</span><span style="color: #000000;">gregorians</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">day</span><span style="color: #0000FF;">,</span><span style="color: #000000;">month</span><span style="color: #0000FF;">,</span><span style="color: #000000;">year</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">day_to_rep</span><span style="color: #0000FF;">(</span><span style="color: #000000;">gre_to_day</span><span style="color: #0000FF;">({</span><span style="color: #000000;">day</span><span style="color: #0000FF;">,</span><span style="color: #000000;">month</span><span style="color: #0000FF;">,</span><span style="color: #000000;">year</span><span style="color: #0000FF;">}))</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">frep</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">month</span><span style="color: #0000FF;">=</span><span style="color: #000000;">13</span><span style="color: #0000FF;">?</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%s %d"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">sansculottides</span><span style="color: #0000FF;">[</span><span style="color: #000000;">day</span><span style="color: #0000FF;">],</span> <span style="color: #000000;">year</span><span style="color: #0000FF;">})</span>
<span style="color: #0000FF;">:</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%d %s %d"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">day</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">republicans</span><span style="color: #0000FF;">[</span><span style="color: #000000;">month</span><span style="color: #0000FF;">],</span> <span style="color: #000000;">year</span><span style="color: #0000FF;">}))</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">frep</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">frep_to_greg</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">frep</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">day</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">month</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">year</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">months</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">days</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">frep</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]<=</span><span style="color: #008000;">'9'</span> <span style="color: #008080;">then</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">day</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">months</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">year</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">scanf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">frep</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d %s %d"</span><span style="color: #0000FF;">)[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">month</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">months</span><span style="color: #0000FF;">,</span><span style="color: #000000;">republicans</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">else</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">days</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">year</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">scanf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">frep</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%s %d"</span><span style="color: #0000FF;">)[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #000000;">day</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">,</span><span style="color: #000000;">sansculottides</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">month</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">13</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">day</span><span style="color: #0000FF;">,</span><span style="color: #000000;">month</span><span style="color: #0000FF;">,</span><span style="color: #000000;">year</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">day_to_gre</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rep_to_day</span><span style="color: #0000FF;">({</span><span style="color: #000000;">day</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">month</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">year</span><span style="color: #0000FF;">}))</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">greg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"%02d %s %d"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">day</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">gregorians</span><span style="color: #0000FF;">[</span><span style="color: #000000;">month</span><span style="color: #0000FF;">],</span> <span style="color: #000000;">year</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">greg</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">test_data</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"22 September 1792"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 1"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"20 May 1795"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Prairial 3"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"15 July 1799"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"27 Messidor 7"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1803"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Fête de la Révolution 11"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"31 December 1805"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"10 Nivôse 14"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"18 March 1871"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"27 Ventôse 79"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"25 August 1944"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"7 Fructidor 152"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"19 September 2016"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Fête du travail 224"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"06 May 1871"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"16 Floréal 79"</span> <span style="color: #0000FF;">},</span> <span style="color: #000080;font-style:italic;">-- Paris Commune begins</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 May 1871"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"3 Prairial 79"</span> <span style="color: #0000FF;">},</span> <span style="color: #000080;font-style:italic;">-- Paris Commune ends</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"09 November 1799"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"18 Brumaire 8"</span> <span style="color: #0000FF;">},</span> <span style="color: #000080;font-style:italic;">-- Revolution ends by Napoléon coup</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"02 December 1804"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"11 Frimaire 13"</span> <span style="color: #0000FF;">},</span> <span style="color: #000080;font-style:italic;">-- Republic ends by Napoléon coronation</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"30 October 1794"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"9 Brumaire 3"</span> <span style="color: #0000FF;">},</span> <span style="color: #000080;font-style:italic;">-- École Normale Supérieure established</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"27 July 1794"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"9 Thermidor 2"</span> <span style="color: #0000FF;">},</span> <span style="color: #000080;font-style:italic;">-- Robespierre falls</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"27 May 1799"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"8 Prairial 7"</span> <span style="color: #0000FF;">},</span> <span style="color: #000080;font-style:italic;">-- Fromental Halévy born</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"22 September 1792"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 1"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"22 September 1793"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 2"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"22 September 1794"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 3"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1795"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 4"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"22 September 1796"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 5"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"22 September 1797"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 6"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"22 September 1798"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 7"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1799"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 8"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1800"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 9"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1801"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 10"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1802"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 11"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"24 September 1803"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 12"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1804"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 13"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1805"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 14"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1806"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 15"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"24 September 1807"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 16"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1808"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 17"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1809"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 18"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 1810"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 19"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"24 September 1811"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 20"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 2015"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 224"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"21 September 2016"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"Fête des récompenses 224"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"22 September 2016"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 225"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"23 September 2016"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"2 Vendémiaire 225"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"22 September 2017"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"1 Vendémiaire 226"</span> <span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span> <span style="color: #008000;">"28 September 2017"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"7 Vendémiaire 226"</span> <span style="color: #0000FF;">}</span> <span style="color: #0000FF;">}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">test_data</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">string</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">greg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">frep</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">test_data</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">],</span>
<span style="color: #000000;">frep2</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">greg_to_frep</span><span style="color: #0000FF;">(</span><span style="color: #000000;">greg</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">greg2</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">frep_to_greg</span><span style="color: #0000FF;">(</span><span style="color: #000000;">frep</span><span style="color: #0000FF;">),</span>
<span style="color: #000000;">ok</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">frep</span><span style="color: #0000FF;">=</span><span style="color: #000000;">frep2</span> <span style="color: #008080;">and</span> <span style="color: #000000;">greg</span><span style="color: #0000FF;">=</span><span style="color: #000000;">greg2</span><span style="color: #0000FF;">?</span><span style="color: #008000;">"ok"</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"**** ERROR ****"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">WINDOWS</span> <span style="color: #008080;">then</span>
<span style="color: #000080;font-style:italic;">-- the windows console does not handle
-- non-basic-latin-ascii characters well...</span>
<span style="color: #000000;">frep</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">substitute_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">frep</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"éêéô"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"eeeo"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%18s <==> %-25s %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">greg</span><span style="color: #0000FF;">,</span><span style="color: #000000;">frep</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ok</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #000080;font-style:italic;">--sanity test:</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #000000;">150000</span> <span style="color: #008080;">do</span> <span style="color: #000080;font-style:italic;">-- (years 1792..~2203)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">rep_to_day</span><span style="color: #0000FF;">(</span><span style="color: #000000;">day_to_rep</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>
<!--</syntaxhighlight>-->
{{out}}
<pre>
22 September 1792 <==> 1 Vendemiaire 1 ok
20 May 1795 <==> 1 Prairial 3 ok
15 July 1799 <==> 27 Messidor 7 ok
23 September 1803 <==> Fete de la Revolution 11 ok
31 December 1805 <==> 10 Nivose 14 ok
18 March 1871 <==> 27 Ventose 79 ok
25 August 1944 <==> 7 Fructidor 152 ok
19 September 2016 <==> Fete du travail 224 ok
06 May 1871 <==> 16 Floreal 79 ok
23 May 1871 <==> 3 Prairial 79 ok
09 November 1799 <==> 18 Brumaire 8 ok
02 December 1804 <==> 11 Frimaire 13 ok
30 October 1794 <==> 9 Brumaire 3 ok
27 July 1794 <==> 9 Thermidor 2 ok
27 May 1799 <==> 8 Prairial 7 ok
22 September 1792 <==> 1 Vendemiaire 1 ok
22 September 1793 <==> 1 Vendemiaire 2 ok
22 September 1794 <==> 1 Vendemiaire 3 ok
23 September 1795 <==> 1 Vendemiaire 4 ok
22 September 1796 <==> 1 Vendemiaire 5 ok
22 September 1797 <==> 1 Vendemiaire 6 ok
22 September 1798 <==> 1 Vendemiaire 7 ok
23 September 1799 <==> 1 Vendemiaire 8 ok
23 September 1800 <==> 1 Vendemiaire 9 ok
23 September 1801 <==> 1 Vendemiaire 10 ok
23 September 1802 <==> 1 Vendemiaire 11 ok
24 September 1803 <==> 1 Vendemiaire 12 ok
23 September 1804 <==> 1 Vendemiaire 13 ok
23 September 1805 <==> 1 Vendemiaire 14 ok
23 September 1806 <==> 1 Vendemiaire 15 ok
24 September 1807 <==> 1 Vendemiaire 16 ok
23 September 1808 <==> 1 Vendemiaire 17 ok
23 September 1809 <==> 1 Vendemiaire 18 ok
23 September 1810 <==> 1 Vendemiaire 19 ok
24 September 1811 <==> 1 Vendemiaire 20 ok
23 September 2015 <==> 1 Vendemiaire 224 ok
21 September 2016 <==> Fete des recompenses 224 ok
22 September 2016 <==> 1 Vendemiaire 225 ok
23 September 2016 <==> 2 Vendemiaire 225 ok
22 September 2017 <==> 1 Vendemiaire 226 ok
28 September 2017 <==> 7 Vendemiaire 226 ok
</pre>
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" line>use v6;
constant @month_names = <
Vendémiaire Brumaire Frimaire Nivôse Pluviôse Ventôse
Line 1,201 ⟶ 1,931:
or Republican_to_Gregorian(Gregorian_to_Republican($g)) != $g;
}
say 'All tests successful.';</
{{Out}}
<pre>All tests successful.</pre>
=={{header|Sidef}}==
{{trans|Perl}}
<
var month_names = %w(
Line 1,572 ⟶ 2,084:
2015-09-23 1 Vendémiaire 224
2016-09-22 1 Vendémiaire 225
2017-09-22 1 Vendémiaire 226</
{{out}}
<pre>
All tests successful.
</pre>
=={{header|Wren}}==
{{trans|Kotlin}}
{{libheader|Wren-date}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="wren">import "./date" for Date
import "./seq" for Lst
import "./fmt" for Fmt
class FrenchRCDate {
/* uses the 'continuous method' for years after 1805 */
static isLeapYear(y) {
var yy = y + 1
return (yy % 4 == 0) && (yy % 100 != 0 || yy % 400 == 0)
}
static parse(frcDate) {
var splits = frcDate.trim().split(" ")
if (splits.count == 3) {
var month = Lst.indexOf(months, splits[1]) + 1
if (month < 1 || month > 13) Fiber.abort("Invalid month.")
var year = Num.fromString(splits[2])
if (year < 1) Fiber.abort("Invalid year.")
var monthLength = (month < 13) ? 30 : (isLeapYear(year) ? 6 : 5)
var day = Num.fromString(splits[0])
if (day < 1 || day > monthLength) Fiber.abort("Invalid day.")
return FrenchRCDate.new(year, month, day)
} else if (splits.count == 4 || splits.count == 5) {
var yearStr = splits[-1]
var year = Num.fromString(yearStr)
if (year < 1) Fiber.abort("Invalid year.")
var scDay = frcDate.trim()[0...-(yearStr.count + 1)]
var day = Lst.indexOf(intercal, scDay) + 1
var maxDay = isLeapYear(year) ? 6 : 5
if (day < 1 || day > maxDay) Fiber.abort("Invalid day.")
return FrenchRCDate.new(year, 13, day)
} else Fiber.abort("Invalid French Republican date.")
}
/* for convenience we treat 'Sansculottide' as an extra month with 5 or 6 days */
static months {
return ["Vendémiaire", "Brumaire", "Frimaire", "Nivôse", "Pluviôse", "Ventôse", "Germinal",
"Floréal", "Prairial", "Messidor", "Thermidor", "Fructidor", "Sansculottide"]
}
static intercal {
return ["Fête de la vertu", "Fête du génie", "Fête du travail",
"Fête de l'opinion", "Fête des récompenses", "Fête de la Révolution"]
}
static introductionDate { Date.new(1792, 9, 22) }
/* year = 1.. month = 1..13 day = 1..30 */
construct new(year, month, day) {
if (year <= 0 || month < 1 || month > 13) Fiber.abort("Invalid date.")
if (month < 13) {
if (day < 1 || day > 30) Fiber.abort("Invalid date.")
} else {
var leap = FrenchRCDate.isLeapYear(year)
if (leap && (day < 1 || day > 6)) Fiber.abort("Invalid date.")
if (!leap && (day < 1 || day > 5)) Fiber.abort("Invalid date.")
}
_year = year
_month = month
_day = day
}
static fromLocalDate(ldate) {
var daysDiff = (ldate - introductionDate).days + 1
if (daysDiff <= 0) Fiber.abort("Date can't be before 22 September 1792.")
var year = 1
var startDay = 1
while (true) {
var endDay = startDay + (isLeapYear(year) ? 365 : 364)
if (daysDiff >= startDay && daysDiff <= endDay) break
year = year + 1
startDay = endDay + 1
}
var remDays = daysDiff - startDay
var month = (remDays / 30).floor
var day = remDays - month * 30
return FrenchRCDate.new(year, month + 1, day + 1)
}
toString {
if (_month < 13) return "%(_day) %(FrenchRCDate.months[_month - 1]) %(_year)"
return "%(FrenchRCDate.intercal[_day - 1]) %(_year)"
}
toLocalDate {
var sumDays = 0
for (i in 1..._year) sumDays = sumDays + (FrenchRCDate.isLeapYear(i) ? 366 : 365)
var dayInYear = (_month - 1) * 30 + _day - 1
return FrenchRCDate.introductionDate.addDays(sumDays + dayInYear)
}
}
var fmt = "d| |mmmm| |yyyy"
var dates = [
"22 September 1792", "20 May 1795", "15 July 1799", "23 September 1803",
"31 December 1805", "18 March 1871", "25 August 1944", "19 September 2016",
"22 September 2017", "28 September 2017"
]
var frcDates = List.filled(dates.count, null)
var i = 0
for (date in dates) {
var thisDate = Date.parse(date, fmt)
var frcd = FrenchRCDate.fromLocalDate(thisDate)
frcDates[i] = frcd.toString
Fmt.print("$-25s => $s", date, frcd)
i = i + 1
}
// now process the other way around
System.print()
for (frcDate in frcDates) {
var thisDate = FrenchRCDate.parse(frcDate)
var lds = thisDate.toLocalDate.format(fmt)
Fmt.print("$-25s => $s", frcDate, lds)
}</syntaxhighlight>
{{out}}
<pre>
22 September 1792 => 1 Vendémiaire 1
20 May 1795 => 1 Prairial 3
15 July 1799 => 27 Messidor 7
23 September 1803 => Fête de la Révolution 11
31 December 1805 => 10 Nivôse 14
18 March 1871 => 27 Ventôse 79
25 August 1944 => 7 Fructidor 152
19 September 2016 => Fête du travail 224
22 September 2017 => 1 Vendémiaire 226
28 September 2017 => 7 Vendémiaire 226
1 Vendémiaire 1 => 22 September 1792
1 Prairial 3 => 20 May 1795
27 Messidor 7 => 15 July 1799
Fête de la Révolution 11 => 23 September 1803
10 Nivôse 14 => 31 December 1805
27 Ventôse 79 => 18 March 1871
7 Fructidor 152 => 25 August 1944
Fête du travail 224 => 19 September 2016
1 Vendémiaire 226 => 22 September 2017
7 Vendémiaire 226 => 28 September 2017
</pre>
|