On 10/22/2021 5:50 PM, Michal Vlasák wrote:
Hello,

On Thu Oct 21, 2021 at 8:04 PM CEST, Hans Hagen via ntg-context wrote:
I cleaned up some more backend code. There were some mails about dates
and such and although the date field in setupinteraction works ok a more
drastic overload is doen with directives. The reason is that the fact
that we can set the date (and traler) is only because it permits
generating pdf files that can be compared. No date as a bad idea anyway.

\setupinteraction[title=My Title]
% \enabledirectives[backend.date=2034-06-07]
\enabledirectives[backend.date=no]
\enabledirectives[backend.trailerid=no]

I checked the backend code and some of the related os functions. I put
together a patch that hopefully fixes some stuff and doesn't break
anything. The changes:

1) Dates parsed by ConTeXt (function converters.totime), such as those
that are input to backend.date, now allow specifying seconds and time
zone information. If there is no timezone the datetime is presumed to be
in local time, otherwise the datetime is offset by the local / specified
time zone difference (because ConTeXt outputs these dates as local times
with local timezone). Additionally both "T" and " " are now allowed as
date/time separator characters. Thus dates output by ConTeXt can be also
fed in.

i made the parser a bit more tolerant

"1234-12-30"
"1234/12/30"
"1234-12-30 23:45"
"1234-12-30 23:45:16"
"1234-12-30  23:45:16"
"1234-12-30T23:45:16+01:00"
"1234-12-30 23:45:16-02:00"
"1234-12-30 23:45:16+05:00"
"1234-12-30 23:45:16 05:00"
"1234-12-30  23:45:16  05:00"

(I'll send you the file to check/test)

2) Fix the os.timezone function. Previously, it could be wrong around
midnight, which I discovered only by chance. The trick is lifted from
http://lua-users.org/wiki/TimeZone, which I hope is OK. The before and
after (I am at +02:00):

     os.localtime()  2021-10-22 01:44:24
     os.now()        2021-10-21 23:44:24
     os.timezone(true)       -22:00


     os.localtime()  2021-10-22 01:46:23
     os.now()        2021-10-21 23:46:23
     os.timezone(true)       +02:00

shouldn't we also offer a -02:00 ? (relative)

I also extended the interface of os.timezone to accommodate 1), but as
this is probably a very public interface, I am not sure if these changes
are OK. If more changes to the interface can be made, I propose to get
rid of the delta parameter, since it seems like a remnant from the past.

maybe later, i need to check other files

Some caching can also be introduced, but I again wasn't sure if this
even would be the final form of the function, so didn't do anything in
that sense, yet.

i'll adapt it to that

3) Don't use %X in time formats. It is specified to be platform
dependent and we want %H:%M:%S everywhere. Also, it would be nice if
lpdf-xmp.lmt would use the os.fulltime() function to format dates (like
back-exp.lmt does), but there are multiple dates with different formats
and purposes and it is probably too late to change now.

(probably not that harmfull on the platforms we support)

the reason for different times is that i never liked the timezone in regular date/time (so only the mandate one had it) but in the end i don't care that much about times/date i never look at (i admit that i never consult any of this pdf meta data)

4) I changed the os.fulltime function, that returns date + time + local
time zone to output the _local_ time instead of UTC time. This is AFAICT
the right way to do times. The PDF spec says:

     If no UT information is specified, the relationship of the specified
     time to UT shall be considered to be GMT. Regardless of whether the
     time zone is specified, the rest of the date shall be specified in
     local time.

     EXAMPLE: For example, December 23, 1998, at 7:52 PM, U.S. Pacific
     Standard Time, is represented by the string D:199812231952-08'00

A test program:


     \enabletrackers[backend.info]
\enabledirectives[backend.date=1234-12-30] % 1234-12-30T00:00:00+02:00
     \enabledirectives[backend.date=1234-12-30 23:45]          % 
1234-12-30T23:45:00+02:00
     \enabledirectives[backend.date=1234-12-30 23:45:16]       % 
1234-12-30T23:45:16+02:00
     \enabledirectives[backend.date=1234-12-30T23:45:16+01:00] % 
1234-12-31T00:45:16+02:00
     \enabledirectives[backend.date=1234-12-30 23:45:16-02:00] % 
1234-12-31T03:45:16+02:00
     \enabledirectives[backend.date=1234-12-30 23:45:16+05:00] % 
1234-12-31T20:45:16+02:00
\starttext
     dummy text
\startluacode
     print("os.timezone(true)", os.timezone(true)) -- +02:00
     print("os.fulltime()", os.fulltime())         -- 2021-10-22 17:38:38+02:00
     print("os.localtime()", os.localtime())       -- 2021-10-22 17:38:38
     print("os.now()", os.now())                   -- 2021-10-22 15:38:38
     \stopluacode
     \stoptext

I don't claim to know LPEG so please check my work. I also know nothing
about XMP, so I didn't check that at all, sorry.

i saw a few things but you can check what i patched later (probably this weekend)

Thanks
 Hans


-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to