xslt format-date not working with format "Fri, 10 May 2019 01:15:00 GMT" - xslt-2.0

When using the format-date function on a date formatted like "Fri, 10 May 2019 01:15:00 GMT", I get an error: Invalid date "Fri, 10 May 2019 01:15:00 GMT" (Non-numeric year component)
I would like to obtain a dd/MM/yyyy format .

If you use XSLT 2 chances are you use a processor like Saxon 9 or AltovaXML which have since 2017 (e.g. Saxon in release 9.8 or later or Altova in releas 2017 or later) updated to support XSLT 3 and XPath 3.1 where you could then make use of the parse-ietf-date function (https://www.w3.org/TR/xpath-functions/#func-parse-ietf-date) to parse your input string into a xs:dateTime on which you could then apply the format-dateTime function:
format-dateTime(parse-ietf-date('Fri, 10 May 2019 01:15:00 GMT'), '[D01]/[M01]/[Y0001]')
https://xqueryfiddle.liberty-development.net/6qM2e2m/1
Your current approach doesn't work as the format-date function works on xs:date and not on arbitrary formatted date strings. That particular format you have shown in your sample can be parsed by the parse-ietf-date function.

Related

TZ Database on Debian Stable for Casablanca ignores the permanent change to DST and Adds an offset of 1

I am on a Debian Stable 9 (stretch), the newly updated TZ database for Africa/Casablanca Table currently states isdst=0 and an offset from UTC of +01.
From the DST in Morocco Wiki page
https://en.wikipedia.org/wiki/Daylight_saving_time_in_Morocco
It is clear that a permanent offset of UTC +1:00 was added from October 2018 and daylight savings is now permanently observed.
But during Ramadan the offset has been traditionally reset to UTC 00:00. But the TZ database denotes that they add an offset of +01 and isdst is set to 1.
This issue is only applicable to Africa/Casablanca.
It seems to be an issue with Debian Stable. Any advice on fixing this issue is appreciated
zdump -v /usr/share/zoneinfo/Africa/Casablanca | grep 2019
/usr/share/zoneinfo/Africa/Casablanca Sun May 5 01:59:59 2019 UT = Sun May 5 02:59:59 2019 +01 isdst=0 gmtoff=3600
/usr/share/zoneinfo/Africa/Casablanca Sun May 5 02:00:00 2019 UT = Sun May 5 02:00:00 2019 +00 isdst=1 gmtoff=0
/usr/share/zoneinfo/Africa/Casablanca Sun Jun 9 01:59:59 2019 UT = Sun Jun 9 01:59:59 2019 +00 isdst=1 gmtoff=0
/usr/share/zoneinfo/Africa/Casablanca Sun Jun 9 02:00:00 2019 UT = Sun Jun 9 03:00:00 2019 +01 isdst=0 gmtoff=3600
From the tzdb 2018h release notes (emphasis mine):
Changes to future timestamps
Guess that Morocco will continue to fall back just before and spring
forward just after Ramadan, the practice since 2012. (Thanks to
Maamar Abdelkader.) This means Morocco will observe negative DST
during Ramadan in main and vanguard formats, and in rearguard format
it stays in the +00 timezone and observes ordinary DST in all months
other than Ramadan. As before, extend this guesswork to the year
2037. As a consequence, Morocco is scheduled to observe three DST transitions in some Gregorian years (e.g., 2033) due to the mismatch
between the Gregorian and Islamic calendars.
It was later confirmed that Morocco did indeed adjust its clocks for Ramadan as predicted. You can read the tz discussion thread, or the article about it on timeanddate.com.
Even the Wikipedia article you cited mentions this:
... An exception was made during the month of Ramadan during which clocks reverted to UTC+00:00 (standard time).

How does Rails handle comparison between TimeWithZone and Date objects?

This could introduce subtle "bugs" (perceived inconsistencies), like the following:
>> Time.zone.parse('Tue, 01 Aug 2017 00:00:00 CEST +02:00') < Date.new(2017,8,1)
=> true
It seems as if Rails converts the Date to a DateTime or TimeWithZone object with '00:00:00 UTC', hence the result. Like this:
>> Date.new(2017,8,1).to_datetime
=> Tue, 01 Aug 2017 00:00:00 +0000
That would explain it. But I would like to know how Rails actually does this, and what type of object it converts it to in the process, to be sure. I didn't find it in the API docs, or the source, but maybe someone can give a step by step explanation.
The source I looked through was: compare_with_coercion
PS: To me it would seem saner that in this type of comparison that Rails would actually convert the TimeWithZone object to a Date object instead, thus resulting in only the date portions to be compared, so that:
>> Time.zone.parse('Tue, 01 Aug 2017 00:00:00 CEST +02:00') == Date.new(2017,8,1)
=> true
Ref:
DateTime API doc
Date API doc

How to set time to dd-MMM-yyyy HH:mm:ss in go?

https://play.golang.org/p/82QgBdoI2G
package main
import "fmt"
import "time"
func main() {
fmt.Println(time.Now().Format("01-JAN-2006 15:04:00"))
}
The output should be like if date time today is 2016-03-03 08:00:00 +0000UTC
Output: 03-MAR-2016 08:00:00
Time should be in 24hr format.
Your layout is incorrect, it should show how the reference time is represented in the format you want, where the reference time is Mon Jan 2 15:04:05 -0700 MST 2006.
Your layout should be:
"02-Jan-2006 15:04:05"
Note the 05 for the seconds part. And since you specified the hours as 15, that is 24-hour format. 3 or 03 is for the 12-hour format.
fmt.Println(time.Now().Format("02-Jan-2006 15:04:05"))
For me it prints:
03-Mar-2016 13:03:10
Also note Jan for months, JAN is not recognized. If you want uppercased month, you may use strings.ToUpper():
fmt.Println(strings.ToUpper(time.Now().Format("02-Mar-2006 15:04:05")))
Output:
03-MAR-2016 13:03:10
Also note that on the Go Playground the time is always set to a constant when your application is started (which is 2009-11-10 23:00:00 +0000 UTC).
fmt.Println(time.Now().Format("02-Jan-2006 15:04:05"))
See Time package constants
The reference time used in the layouts is the specific time:
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445. Since MST is GMT-0700, the reference time can be thought of as
01/02 03:04:05PM '06 -0700

Rails - Time arithmetic

I was playing time arithmetic in rails console. I have subtracted two different times and got back a long number, please see below my code.
a = User.find(1).updated_at # returns Mon, 03 Mar 2014 11:07:43 UTC +00:00
b = User.find(1).created_at # returns Mon, 03 Mar 2014 08:36:50 UTC +00:00
a - b # returns 9053.699814796448
My question is. What is this number 9053.699814796448? Is it time? What is it's unit? and how is that calculated? Is it possible to change the default unit of the outcome?
Thanks
a - b gives you the time in seconds. Check out the Time#- .

How to use RFC2822 format date in a URL?

How do I pass date in RFC2822 format, to an URL in GET method:
e.g I want to pass 18th jan 2013 as min_date_created in the URL https://www.xyz.com/orders
18th jan 2013 in RFC format is ==> Fri, 18 Jan 2013 17:58:49 +0000
how can I pass it to URL?
TIA!
Instead of passing the date as a string, you could convert it to the number of milliseconds since midnight Jan 1, 1970:
var time = new Date('Fri, 18 Jan 2013 17:58:49 +0000').getTime(); // 1358531929000
widow.location.href = 'https://www.xyz.com/orders?min_date_created='+time;
This way you won't have encoding problems.
Or you could also use encodeURIComponent(), see URL encode sees “&” (ampersand) as “&” HTML entity

Resources