CalendarConversion: update styling.
- New date outputs with per-calendar months. - More standardized CSS. I'm less than excited that you can't enter the other calendars with month names, but that'll have to be ok for now.master
parent
06d00f2a70
commit
109bd64681
|
@ -7,7 +7,10 @@ with 'DDG::GoodieRole::Dates';
|
|||
use Date::Hijri;
|
||||
use Date::Jalali2;
|
||||
|
||||
use YAML::XS qw(Load);
|
||||
|
||||
zci answer_type => "calendar_conversion";
|
||||
zci is_cached => 0;
|
||||
|
||||
primary_example_queries '22/8/2003 to the hijri calendar';
|
||||
secondary_example_queries '23/6/1424 hijri to gregorian';
|
||||
|
@ -21,23 +24,15 @@ attribution github => ['http://github.com/mattlehning', 'mattlehning'],
|
|||
|
||||
triggers any => 'hijri', 'gregorian', 'jalali';
|
||||
|
||||
my %calendars = (
|
||||
'gregorian' => ['Gregorian calendar', '<a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a>'],
|
||||
'hijri' => ['Hijri calendar', '<a href="https://en.wikipedia.org/wiki/Hijri_calendar">Hijri calendar</a>'],
|
||||
'jalali' => ['Jalali calendar', '<a href="https://en.wikipedia.org/wiki/Jalali_calendar">Jalali calendar</a>'],
|
||||
);
|
||||
|
||||
my $calendars = Load(scalar share('calendars.yml')->slurp);
|
||||
|
||||
my $datestring_regex = datestring_regex();
|
||||
|
||||
# This function returns either the HTML version of the output or the text version.
|
||||
sub output {
|
||||
my ($calendar_first, $calendar_second, $input_date, $converted_date, $is_html) = @_;
|
||||
sub format_date {
|
||||
my ($d, $m, $y, $cal) = @_;
|
||||
|
||||
return
|
||||
"$input_date on the "
|
||||
. $calendars{$calendar_first}[$is_html]
|
||||
. " is $converted_date on the "
|
||||
. $calendars{$calendar_second}[$is_html] . '.';
|
||||
return join(' ', $d, $calendars->{$cal}->[$m - 1], $y, '(' . ucfirst $cal . ')');
|
||||
}
|
||||
|
||||
handle query_lc => sub {
|
||||
|
@ -75,12 +70,10 @@ handle query_lc => sub {
|
|||
($od, $om, $oy) = ($t->jal_day, $t->jal_month, $t->jal_year);
|
||||
($od, $om, $oy) = g2h($od, $om, $oy) if ($output_calendar eq "hijri");
|
||||
}
|
||||
my $date_format = '%s-%02d-%02d';
|
||||
my $input_date = sprintf($date_format, $y, $m, $d);
|
||||
my $converted_date = sprintf($date_format, $oy, $om, $od);
|
||||
my $input_date = format_date($d, $m, $y, $input_calendar);
|
||||
my $converted_date = format_date($od, $om, $oy, $output_calendar);
|
||||
|
||||
return output($input_calendar, $output_calendar, $input_date, $converted_date, 0),
|
||||
html => output($input_calendar, $output_calendar, $input_date, $converted_date, 1);
|
||||
return $input_date. ' is '. $converted_date, html => "<div class='zci--calendarconversion text--primary'>$input_date <span class='text--secondary'>is</span> $converted_date</div>";
|
||||
};
|
||||
|
||||
sub g2j {
|
||||
|
@ -90,4 +83,6 @@ sub g2j {
|
|||
return ($t->jal_day, $t->jal_month, $t->jal_year);
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
.zci--answer .zci--calendarconversion {
|
||||
font-size: 1.5em;
|
||||
font-weight: 300;
|
||||
padding-top: .25em;
|
||||
padding-bottom: .25em;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
---
|
||||
gregorian:
|
||||
- January
|
||||
- Feburary
|
||||
- March
|
||||
- April
|
||||
- May
|
||||
- June
|
||||
- July
|
||||
- August
|
||||
- September
|
||||
- October
|
||||
- November
|
||||
- December
|
||||
hijri:
|
||||
- Muharram
|
||||
- Safar
|
||||
- Rabia Awal
|
||||
- Rabia Thani
|
||||
- Jumaada Awal
|
||||
- Jumaada Thani
|
||||
- Rajab
|
||||
- Sha'ban
|
||||
- Ramadan
|
||||
- Shawwal
|
||||
- Dhul-Qi'dah
|
||||
- Dhul-Hijjah
|
||||
jalali:
|
||||
- Farvardin
|
||||
- Ordibehesht
|
||||
- Khordad
|
||||
- Tir
|
||||
- Mordad
|
||||
- Shahrivar
|
||||
- Mehr
|
||||
- Aban
|
||||
- Azar
|
||||
- Dey
|
||||
- Bahman
|
||||
- Esfand
|
|
@ -8,83 +8,51 @@ use DDG::Test::Goodie;
|
|||
zci answer_type => 'calendar_conversion';
|
||||
zci is_cached => 0;
|
||||
|
||||
my @g22h = (
|
||||
'22 August 2003 (Gregorian) is 23 Jumaada Thani 1424 (Hijri)',
|
||||
html =>
|
||||
"<div class='zci--calendarconversion text--primary'>22 August 2003 (Gregorian) <span class='text--secondary'>is</span> 23 Jumaada Thani 1424 (Hijri)</div>"
|
||||
);
|
||||
my @h23g = (
|
||||
'23 Jumaada Thani 1424 (Hijri) is 22 August 2003 (Gregorian)',
|
||||
html =>
|
||||
"<div class='zci--calendarconversion text--primary'>23 Jumaada Thani 1424 (Hijri) <span class='text--secondary'>is</span> 22 August 2003 (Gregorian)</div>"
|
||||
);
|
||||
my @g22j = (
|
||||
'22 August 2003 (Gregorian) is 31 Mordad 1382 (Jalali)',
|
||||
html =>
|
||||
"<div class='zci--calendarconversion text--primary'>22 August 2003 (Gregorian) <span class='text--secondary'>is</span> 31 Mordad 1382 (Jalali)</div>"
|
||||
);
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw(DDG::Goodie::CalendarConversion)],
|
||||
'22/8/2003 to hijri' => test_zci(
|
||||
'2003-08-22 on the Gregorian calendar is 1424-06-23 on the Hijri calendar.',
|
||||
html =>
|
||||
'2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a> is 1424-06-23 on the <a href="https://en.wikipedia.org/wiki/Hijri_calendar">Hijri calendar</a>.'
|
||||
),
|
||||
'22/8/2003 to the hijri calendar' => test_zci(
|
||||
'2003-08-22 on the Gregorian calendar is 1424-06-23 on the Hijri calendar.',
|
||||
html =>
|
||||
'2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a> is 1424-06-23 on the <a href="https://en.wikipedia.org/wiki/Hijri_calendar">Hijri calendar</a>.'
|
||||
),
|
||||
'22,8,2003 to hijri' => test_zci(
|
||||
'2003-08-22 on the Gregorian calendar is 1424-06-23 on the Hijri calendar.',
|
||||
html =>
|
||||
'2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a> is 1424-06-23 on the <a href="https://en.wikipedia.org/wiki/Hijri_calendar">Hijri calendar</a>.'
|
||||
),
|
||||
'23/6/1424 in hijri to gregorian years' => test_zci(
|
||||
'1424-06-23 on the Hijri calendar is 2003-08-22 on the Gregorian calendar.',
|
||||
html =>
|
||||
'1424-06-23 on the <a href="https://en.wikipedia.org/wiki/Hijri_calendar">Hijri calendar</a> is 2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a>.'
|
||||
),
|
||||
'23/6/1424 hijri to gregorian' => test_zci(
|
||||
'1424-06-23 on the Hijri calendar is 2003-08-22 on the Gregorian calendar.',
|
||||
html =>
|
||||
'1424-06-23 on the <a href="https://en.wikipedia.org/wiki/Hijri_calendar">Hijri calendar</a> is 2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a>.'
|
||||
),
|
||||
'22/8/2003 to jalali' => test_zci(
|
||||
'2003-08-22 on the Gregorian calendar is 1382-05-31 on the Jalali calendar.',
|
||||
html =>
|
||||
'2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a> is 1382-05-31 on the <a href="https://en.wikipedia.org/wiki/Jalali_calendar">Jalali calendar</a>.'
|
||||
),
|
||||
'22/8/2003 to hijri' => test_zci(@g22h),
|
||||
'22/8/2003 to the hijri calendar' => test_zci(@g22h),
|
||||
'22,8,2003 to hijri' => test_zci(@g22h),
|
||||
'23/6/1424 in hijri to gregorian years' => test_zci(@h23g),
|
||||
'23/6/1424 hijri to gregorian' => test_zci(@h23g),
|
||||
'22/8/2003 to jalali' => test_zci(@g22j),
|
||||
'31/5/1382 jalali to gregorian' => test_zci(
|
||||
'1382-05-31 on the Jalali calendar is 2003-08-22 on the Gregorian calendar.',
|
||||
'31 Mordad 1382 (Jalali) is 22 August 2003 (Gregorian)',
|
||||
html =>
|
||||
'1382-05-31 on the <a href="https://en.wikipedia.org/wiki/Jalali_calendar">Jalali calendar</a> is 2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a>.'
|
||||
"<div class='zci--calendarconversion text--primary'>31 Mordad 1382 (Jalali) <span class='text--secondary'>is</span> 22 August 2003 (Gregorian)</div>",
|
||||
),
|
||||
'31/5/1382 jalali to hijri' => test_zci(
|
||||
'1382-05-31 on the Jalali calendar is 1424-06-23 on the Hijri calendar.',
|
||||
'31 Mordad 1382 (Jalali) is 23 Jumaada Thani 1424 (Hijri)',
|
||||
html =>
|
||||
'1382-05-31 on the <a href="https://en.wikipedia.org/wiki/Jalali_calendar">Jalali calendar</a> is 1424-06-23 on the <a href="https://en.wikipedia.org/wiki/Hijri_calendar">Hijri calendar</a>.'
|
||||
"<div class='zci--calendarconversion text--primary'>31 Mordad 1382 (Jalali) <span class='text--secondary'>is</span> 23 Jumaada Thani 1424 (Hijri)</div>"
|
||||
),
|
||||
'23/6/1424 in hijri to jalali date' => test_zci(
|
||||
'1424-06-23 on the Hijri calendar is 1382-05-31 on the Jalali calendar.',
|
||||
'23 Jumaada Thani 1424 (Hijri) is 31 Mordad 1382 (Jalali)',
|
||||
html =>
|
||||
'1424-06-23 on the <a href="https://en.wikipedia.org/wiki/Hijri_calendar">Hijri calendar</a> is 1382-05-31 on the <a href="https://en.wikipedia.org/wiki/Jalali_calendar">Jalali calendar</a>.'
|
||||
),
|
||||
'August 22nd, 2003 to jalali' => test_zci(
|
||||
'2003-08-22 on the Gregorian calendar is 1382-05-31 on the Jalali calendar.',
|
||||
html =>
|
||||
'2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a> is 1382-05-31 on the <a href="https://en.wikipedia.org/wiki/Jalali_calendar">Jalali calendar</a>.'
|
||||
),
|
||||
'22 Aug 2003 to Hijri' => test_zci(
|
||||
'2003-08-22 on the Gregorian calendar is 1424-06-23 on the Hijri calendar.',
|
||||
html =>
|
||||
'2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a> is 1424-06-23 on the <a href="https://en.wikipedia.org/wiki/Hijri_calendar">Hijri calendar</a>.'
|
||||
),
|
||||
'22/8/2003 in the hijri calendar' => test_zci(
|
||||
'2003-08-22 on the Gregorian calendar is 1424-06-23 on the Hijri calendar.',
|
||||
html =>
|
||||
'2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a> is 1424-06-23 on the <a href="https://en.wikipedia.org/wiki/Hijri_calendar">Hijri calendar</a>.'
|
||||
),
|
||||
'22nd Aug 2003 in jalali' => test_zci(
|
||||
'2003-08-22 on the Gregorian calendar is 1382-05-31 on the Jalali calendar.',
|
||||
html =>
|
||||
'2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a> is 1382-05-31 on the <a href="https://en.wikipedia.org/wiki/Jalali_calendar">Jalali calendar</a>.'
|
||||
),
|
||||
'8-22-2003 in hijri years' => test_zci(
|
||||
'2003-08-22 on the Gregorian calendar is 1424-06-23 on the Hijri calendar.',
|
||||
html =>
|
||||
'2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a> is 1424-06-23 on the <a href="https://en.wikipedia.org/wiki/Hijri_calendar">Hijri calendar</a>.'
|
||||
),
|
||||
'August 22 2003 in jalali date' => test_zci(
|
||||
'2003-08-22 on the Gregorian calendar is 1382-05-31 on the Jalali calendar.',
|
||||
html =>
|
||||
'2003-08-22 on the <a href="https://en.wikipedia.org/wiki/Gregorian_calendar">Gregorian calendar</a> is 1382-05-31 on the <a href="https://en.wikipedia.org/wiki/Jalali_calendar">Jalali calendar</a>.'
|
||||
"<div class='zci--calendarconversion text--primary'>23 Jumaada Thani 1424 (Hijri) <span class='text--secondary'>is</span> 31 Mordad 1382 (Jalali)</div>"
|
||||
),
|
||||
'August 22nd, 2003 to jalali' => test_zci(@g22j),
|
||||
'22 Aug 2003 to Hijri' => test_zci(@g22h),
|
||||
'22/8/2003 in the hijri calendar' => test_zci(@g22h),
|
||||
'22nd Aug 2003 in jalali' => test_zci(@g22j),
|
||||
'8-22-2003 in hijri years' => test_zci(@g22h),
|
||||
'August 22 2003 in jalali date' => test_zci(@g22j),
|
||||
'22nd Aug 2003 in gregorian time' => undef,
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue