How to set base timestamp for relative date parsing in NLPCraft? - nlp

I'm working with nlpcraft to build a parsing system for scheduling. Users are asked when they will be doing certain activities and they can respond with relative or absolute dates, such as "tuesday and wednesday" or "not until 8/15".
While nlpcraft has very nice relative date parsing, near as I can tell it always parses dates relative to the current system time in UTC. Not only does this complicate testing (because the input is relative while the output is absolute), it means that if the server does not parse the input close to the time the user wrote it, relative dates may be parsed incorrectly. For example, if the user says "tomorrow" at 11PM on a Sunday, but the server doesn't parse it until 5AM on Monday, it might result in Tuesday instead of Monday.
I looked into NCDateEnricher where this all seems to happen and then parsing routine computes a base time as the current system time. I didn't see a way to override this with a config variable or request parameter -- am I missing something?

UTC time server on server-side allows users to easily convert times to local timezone. It's the simplest way to support different timezone users with one server.
If you aren't satisfied with nlpcart provided date NER, you can look at date/time NERS from opennlp/stanford/spacy/google, which can be simply used with nlpcraft system (https://nlpcraft.incubator.apache.org/integrations.html)

Related

how to print time format in yyyy-MM-ddTHH:mm:ssZ using date command in linux

I need time in this format 'yyyy-MM-ddTHH:mm:ssZ'(e.g 1985-04-12T23:20:50.52Z) using date command in Linux. Can you help me on this?
The exact reproduction of Universal Coordinated Time (UTC) (a/k/a Zulu time) with Hundredths of a second would require fashioning a custom date string and calling date -u.
Note: to address the correct assertion in the comment by Toby Speight that there is a potential for a 1-second difference between the date representation held by d and that by n in the original answer due to using separate date calls, you can alleviate the concern by using a single call to date (and thank you again Toby for reminding me we can use printf field-width modifiers to truncate the nanosecond field), e.g.
date -u +'%FT%T.%2NZ'
Example Result
$ date -u +'%FT%T.%2NZ'
2018-04-14T17:45:28.20Z
This will avoid the 1-second potential difference due to two date calls.

DateTime on local machine is different then Azure

I know this might be a simple question but I'm not sure how to solve it.
When I run this bit of code on my local machine
if (someDateTime < DateTime.Now)
// do something
'DateTime.Now' gives me the current date time for my time zone, but when I run it in Azure 'DateTime.Now' gives me a different time
ex. local machine says 12:00AM and Azure says 8:13AM
What do I need to do to compare a time 'someDAteTime' with a time for a user on my site (his/her current DateTime.Now) ?
There should be a Utc() method on that DateTime instance, every programming language has something similar since probably the Atari.
If this is .NET (Full/Core), just use DateTime.UtcNow.
More on that here —
What is the difference between DateTime.UtcNow and DateTime.Now.ToUniversalTime()
The essence here is that you always compare UTC time to UTC time, disregarding zone shift. Moreover, all Azure services report time in UTC "out of the box".
I assume that you are using javascript at client side.
If you want to compare dates you should always use ISO Date (https://en.wikipedia.org/wiki/ISO_8601)with a timezone.
You can use this library in order to use different time zones: https://momentjs.com/timezone/
And this library to compare dates:
https://momentjs.com/
Please take care that the user can modify the date on the client side, so if you need to validate a date for a critical feature you should do this validation on the server side.

Node JS new Date one hour mismatch

When I print this:
const from = new Date();
console.log(from);
I get this: 2017-02-13T22:55:01.395Z
By the way it's 23:55. Why is there a one-hour mismatch?
When I do this:
console.log(from.getHours())
I get it right (23) which is fine. What is happening?
The string representation of from printed in your question is expressed in UTC, which you can tell by the trailing Z.
However, from is also capable of expressing the point in time it represents internally in local time, according to your time zone: from.toLocaleString()
Similarly, .getHours() returns the time-of-day hour in local time.
The implication is that your local time is 1 hour ahead of UTC, such as in Western Europe, for instance (while DST isn't in effect).
In other words: The output you're getting is as designed.

NodaTime supports relative time display?

I have a situation where the relative time is more important to a user than an absolute time. So it's more important to be able to quickly say "event happened 5 days and 5 hours ago" than "event happened at 1 PM CDT and it's 5 PM CST 5 days later now."
We store our dates in UTC and convert to display for the user:
pDateTime = DateTime.SpecifyKind(pDateTime, DateTimeKind.Utc);
DateTimeZone dateTimeZone = DateTimeZoneProviders.Tzdb[pCurrentUser.PreferredTimezone];
return Instant.FromDateTimeUtc(pDateTime).InZone(dateTimeZone).ToString("HH':'mm':'ss' 'MM'/'dd'/'yy' 'x", CultureInfo.InvariantCulture);
We'll be using NodaTime 1.2 when it's fully out and just used vanilla ToString before.
However, times using this pattern end up using the daylight status of the time as opposed to the current daylight status. This means that times look something like: 16:15:32 10/25/13 CDT even though we have now transitioned to CST.
It is an absolute measure of the time. This forces the user to do the logic: "How long ago was that? Is it daylight saving time now? If so, the difference is x. If not, I have to add or subtract an hour? That makes the difference y."
Meanwhile, a relative measure of the time would display 15:15:32 10/25/13 CST in the absence of DST. This forces the user to do no conversions and allows them to compute what that time means in context much easier.
In a display that has numerous dates, it can get tricky to do the absolute time logic over the entire set. Doing it once is tricky to get right. However, a friendly relative string like "posted 5 hours ago" also forces them to resolve both the date and time themselves - that information is still important.
A compromise might be to do the posted blank hours/minutes ago for the first 24 hours or to include both the friendly string and absolute time - these are both patterns I've seen done.
But ignoring those, is there a way in NodaTime to imbue a time with a specific daylight status in order to get times displaying in a relative context?
However, times using this pattern end up using the daylight status of the time as opposed to the current daylight status. This means that times look something like: 16:15:32 10/25/13 CDT even though we have now transitioned to CST.
Yes, and it should. Displaying a date/time with CST despite that date/time occurring in CDT would be very odd, IMO.
So it's more important to be able to quickly say "event happened 5 days and 5 hours ago" than "event happened at 1 PM CDT and it's 5 PM CST 5 days later now."
In that case you shouldn't be displaying a date/time at all, in my view. Convert both ZonedDateTime values to Instant, take the Duration between them, and then you can see that it's 5 days and 5 hours ago. (I can't remember how much help we provide with that - you may need to manually take the number of ticks and divide by NodaConstants.TicksPerStandardDay etc. Look at DurationPattern to see if it helps though.)
Alternatively, if you really want to display a date and time, but still easily be able to extract the difference between them mentally, two options suggest themselves:
Use OffsetDateTime instead; there you could force the offsets to be the same, although I still think it would be odd to display an offset which wasn't actually the current offset in the zone you were observing the time in. Or you could just display the relevant offset at the time, so -5 for CST and -4 for CDT.
Just display everything in UTC, so that daylight saving transitions are irrelevant.
Note that you can't get months between the two ZonedDateTime values, as we're dealing with an elapsed time (a duration) rather than calendar-logical arithmetic (a period).

Do NodaTime constructors accept 24 in the Hours parameter

I am hoping to get a quick answer to one question about NodaTime before downloading it. So far, I am reading about NodaTime and its API and it seems very carefully thought out.
I hope it might help eliminate some of the chaos I've been encountering in an application that has a database back-end, a desktop client with a database provider, and a web client that must run on the major browsers. The support for ISO 8601 on DateTime and Time varies greatly on the various database, database provider, and web platforms. Internet Explorer, for example, follows ISO 8601 but SQL Server does not; web UI timepickers do not because Chrome does not.
QUESTION: In NodaTime, is 24:00 a valid Time value? Is 24 a valid argument for the hours parameter of its Time constructors?
BACKGROUND: ISO 8601 allows for two representations of midnight: 00:00 for "midnight this morning" and 24:00 for "midnight tonight". When the DateTime object is on the time-line, a date whose time element has 24:00 coincides with the next day at 00:00. They are the same time-line instant with two different representations, both representations valid per ISO.
A Time-only value is detached from the time-line. A time of 00:00 occurs at the beginning of the detached 24-hour day and a Time-only value of 24:00 is 24 hours after 00:00. A Time type should accept 24 in the hour. When 24 is the hour the maximum value for seconds and milliseconds and ticks is 0 (unless modulo arithmetic is involved and the time rolls over, so that 24:01 is 00:01 -- but ISO has nothing to say about this implementation detail, IIRC).
We accept 24:00 when parsing a LocalDateTime, but not 24:01.
This was issue 153, implemented in revision f7ac0365d8ca.
Unfortunately this was after the 1.0 release, so you'll either need to grab the current code, or wait for 1.1 to be released (hopefully soon).
We don't currently accept it when parsing just a LocalTime. If you want that, please log a feature request - we'd probably look at it for 1.2 (which will have a lot of text features), although I'm not sure what the representation would look like. (LocalTime itself doesn't support the idea of "end-of-day midnight".)

Resources