How do I format ${date} in Pandoc HTML output? - pandoc

I have a LaTeX document that I convert to HTML using Pandoc. My template references the $date$ variable like so:
$if(date)$
<p>$date$</p>
$endif$
As usual, the value of $date$ is the ISO formatted date (e.g., 2022-06-17 for today). I want to format it so that it has a human-readable format, so that I can get this output:
<p>17 Jun 2022</p>
Usually, one can achieve this using format strings (for the above example: %d %b %Y). Is there a way to do that for the Pandoc's output?

A simple Lua filter can achieve this.
The following filter code is adapted from Setting the date in the metadata from the Pandoc documentation.
-- filters/date-format.lua
function Meta(meta)
if meta.date then
local format = "(%d+)-(%d+)-(%d+)"
local y, m, d = pandoc.utils.stringify(meta.date):match(format)
local date = os.time({
year = y,
month = m,
day = d,
})
local date_string = os.date("%d %b %Y", date)
meta.date = pandoc.Str(date_string)
return meta
end
end
---
# test.md
title: My Title
date: 2022-06-18
---
<!-- templates/date.html -->
$if(date)$
<p>$date$</p>
$endif$
Compile with the command pandoc --data-dir=. --template=date --lua-filter=date-format.lua test.md -o test.html.
The output should be <p>18 Jun 2022</p>.

Related

Change the format of date from "mm/dd/yyyy" to "Month dd, yyyy" in Ruby

I am trying to extract date from XML and compare it with the date in a PDF.
I am using Nokogiri to get the date from XML and PDF-Reader to read the date from PDF.
But the date in XML is in "mm/dd/yyyy" format and the date in PDF is in "Month dd, yyyy" format.
XML Tag:
<LetterSendDate>02/29/2016</LetterSendDate>
Extracting the Date from xml using Nokogiri:
#reader = file('C:\Users\ecz560\Desktop\30004_Standard.pdf').parse_pdf
#xml = file('C:\Users\ecz560\Desktop\30004_Standard.xml').parse_xmlDoc
#LettersendDate = #xml.xpath("//Customer[RTLtr_Loancust='0163426']//RTLtr_LetterSendDate").map(&:text)
Comparing the XML date with the date in PDF:
page_index = 0
#reader.pages.each do |page|
page_index = page_index+1
if expect(page.text).to include #LettersendDate
valid_text = "Given text is present in -- #{page_index}"
puts valid_text
end
end
but expect(page.text) returns February 29, 2016
so it is giving me error while comparing
Error
if expect(page.text).to include #LettersendDate
TypeError: no implicit conversion of String into Array
How can I convert the date from "mm/dd/yy" format to "Month dd, yyyy format" ?

i118n with Simpleform for date format from string

I am using jquery.datetime that inputs a date as a string into simpleform. It is supplying the date as %d %m %Y which is what I want but I am getting %m %d %Y because that is apparently the default for Simple Form:
The solution which is the same as for jquery datepicker is to add a custom input:
class DatePickerInput < SimpleForm::Inputs::StringInput
def input
value = object.send(attribute_name) if object.respond_to? attribute_name
input_html_options[:value] ||= I18n.localize(value) if value.present?
input_html_classes << "datepicker"
super # leave StringInput do the real rendering
end
end
This appears to be fine but it uses i118n to read the format I have a en.yml and a simple_form.en.yml initializer files under locales. I have tried adding:
datetime:
formats:
default: %d %m %Y
To both separately but when I do I get the following error message that says;
CAN NOT LOAD TRANSLATIONS
How can I modify my date time format?
Looks like you have problem with yml formatting - it's one space instead of two. Try to change it to:
datetime:
formats:
default: %d %m %Y
The Answer is partially correct but the format also needs to be quoted:
datetime:
formats:
default: '%d %m %Y'

VbScript FormateDateTime function showing different format for two files

I have got below code, where I am sending the formatted date and time to my XSLT and which is giving a XML as output.
#importXSLT "tcm:228-190529-2048" As expandXSLT
#importXSLT "tcm:228-642694-2048" As renderXSLT
Dim xml, currentDateTime, datLong , datLongTime , fullDate
Set xml = getNewDomDocument()
xml.loadXML TDSE.GetListPublications(3)
expandXSLT.input = xml
Call expandXSLT.addParameter("publication", Component.Publication.Id)
expandXSLT.transform
xml.loadXML(expandXSLT.output)
'WriteOut xml.xml
currentDateTime = now()
datLong = FormatDateTime(currentDateTime, 1)
datLongTime = FormatDateTime(currentDateTime, 3)
fullDate = datLong &" "& datLongTime
renderXSLT.input = xml
Call renderXSLT.addParameter("currentPublishedDate", CStr(fullDate))
renderXSLT.transform
WriteOut renderXSLT.output
Set xml = Nothing
Now above logic for doing date formatting is same for two outputted XML, but suprising I am getting different output for both the files.
First File gives - Sunday, October 23, 2011 8:52:36 AM as output
Second File gives - 23 October 2011 09:14:45 as output.
Please suggest what can be reason as well as solution also, and one more thing if I want output as below for both the file as 23 October 2011 09:14:45 AM
Thanks!!
Before you do the date formatting, try to explicitly set the locale using something like SetLocale(2057).
2057 is UK format which seems to be what you want, otherwise look at this Locale ID Chart to find the correct value.

In KRL How can I get the current year, month, and day?

I am working on an application in which I need to get the current year, month, and day. Is there a way to get this information in the pre block of a rule?
Can I get this data as a string or a number or both?
There are currently time functions documented on http://docs.kynetx.com/docs/Time but none of them seem to work for what I am trying to do.
Is there a way to set the timezone when getting this data?
I was able to do it using strftime which appears to be an undocumented feature so use with caution.
ruleset a60x518 {
meta {
name "date-test"
description <<
date-test
>>
author "Mike Grace"
logging on
}
rule testing {
select when pageview ".*"
pre {
retTime = time:strftime(time:now({"tz":"America/Denver"}), "%c");
month = time:strftime(time:now({"tz":"America/Denver"}), "%B");
year = time:strftime(time:now({"tz":"America/Denver"}), "%Y");
day = time:strftime(time:now({"tz":"America/Denver"}), "%d");
}
{
notify("time",retTime) with sticky = true;
notify("month",month) with sticky = true;
notify("year",year) with sticky = true;
notify("day",day) with sticky = true;
}
}
}
App run on example.com twice. Once with the timezone set to New York and onother time set to Denver
I used this site http://www.statoids.com/tus.html to get the correct strings to use for the timezone. I have no idea if they all work. I just found this site and tried a few and they worked so use with caution.
Perhaps the docs got reverted. For convenience, here is the documentation for strftime:
time:strftime()
Convert a datetime string to a different format
Usage
time:strftime(`<string>`,`<format>`)
Valid format arguments to strftime follow the POSIX strftime conventions.
Samples
time:strftime(xTime,”%F %T”) # 2010-10-06 18:15:24
time:strftime(xTime,”%F”) # 2010-10-06
time:strftime(xTime,”%T”) # 18:19:29
time:strftime(xTime,”%A %d %b %Y”) # Wednesday 06 Oct 2010
time:strftime(xTime,”%c”) # Oct 6, 2010 6:25:55 PM
The other time functions:
time:now()
Current datetime based upon user’s location data
Usage
time:now()
time:now({“tz” : <timezone>)
time:new()
Create a new RFC 3339 datetime string from a string (allows some flexibility in how the source string is formatted)
Usage
time:new() # Equivalent to time:now()
time:new(<string>)
Valid formats for the datetime source string can be found in ISO8601 (v2000).
time:add()
Add (or subtract) a specific number of time units to a source string
Usage
time:add(<string>,{<unit> : n})

Convert date object to string in boost

Using the boost library how would I convert a date object:
date d(2010,10,01);
to a string with the format: DD-mmm-YYYY, so that variable
d would become "01-Oct-2010".
Now there are number of functions for converting a date object to a
string such as
std::string to_simple_string(date d)
which returns a string in the format YYYY-mmm-DD. But I was unable
to find the format I need.
Thanks!
Have you read the documentation about date facet? The example appears like it should work for your scenario.
//example to customize output to be "LongWeekday LongMonthname day, year"
// "%A %b %d, %Y"
date d(2005,Jun,25);
date_facet* facet(new date_facet("%A %B %d, %Y"));
std::cout.imbue(std::locale(std::cout.getloc(), facet));
std::cout << d << std::endl;
// "Saturday June 25, 2005"

Resources