how to pass a date/time reference in a call to a basic duckling server? - wit.ai

Any pointers on how to pass a date/time reference to a basic, vanilla duckling server?
I'm using duckling for parsing text. When looking for time expressions, I need to pass in a reference date/time.
A reference date/time gives me an anchor for expressions like "yesterday" and "today."
e.g.
reference date = April 1, 2018 => "1 week ago" = March 25, 2018.
reference time = April 1, 2018, 3pm => "in 8 hours" = April 1, 2018, 11pm
The duckling repo site has instructions on how to make a basic server run locally, that you can then call with
curl -XPOST http://0.0.0.0:8000/parse --data 'locale=en_GB&text=tomorrow at eight'
but not many more examples are provided that I could find. I can see in ExampleMain.hs that dims and lang are also options as parameters along text and locale, but nothing on reference date.

curl -XPOST http://0.0.0.0:8000/parse --data 'locale=en_GB&text=tomorrow at eight&reftime=<unix epoch in millisecond>'
Reference:
https://github.com/facebook/duckling/issues/166

Related

Swift 3 playground logs dates in local format. How?

If you run a line like this in a Playground in the US:
let today = Date()
You'll see output like this to the right of the source code:
"Sep 26, 2016, 8:17 PM"
That appears to be the date, displayed in the local time zone, using medium date and time style.
How does that work?
If you try to print the date:
print("today = \(today)"
You'll see "Today = 2016-09-27 00:18:55 +0000\n", which is UTC, and appears to be unix date format.
What function is the Playground using to display the date when you first create a date? Is there a way to get to that output format from code or from the debug console?
Up until now I've created a date formatter that I use to log dates, display them in the console, etc.
It's lurking in CustomPlaygroundQuickLookable protocol, which Date conforms to:
if case .text(let str) = today.customPlaygroundQuickLook {
print(str)
}

Podio API filtering by date range

I'm trying to filter tasks by date range and I'm getting errors whatever I try. This is how my request looks like: http://api.podio.com/task?completed=true&created_on%5Bfrom%5D=2016-06-23&created_on%5Bto%5D=2016-06-28&limit=100&offset=0&sort_by=rank&sort_desc=false&space=4671314
Here I'm trying to filter by created_on and I'm suplying {from: "2016-06-23", to: "2016-06-28"} but it's always returning the same error - invalid filter. I'm trying to filter tasks that are created in the last 5 days here.
The tasks API reference can be found in their API docs.
What am I doing wrong?
Date ranges can be separated by -.
To display "all my tasks created between 1st Jan 2014 and 1st Jan 2016" :-
/task?created_on=2014-01-01-2016-01-01&responsible=0'
Podio API get task filtering by date range use below :
/task/?created_on=2017-04-25-2017-05-01&offset=0&sort_by=rank&sort_desc=false&space=xxxxxxx

RRULE explanaiton using BYDAY and BYSETPOS

I am trying to parse an RRULE and display what weeks in the month a recurrence event is valid for. I have looked at the RFC2445 doc (http://www.ietf.org/rfc/rfc2445.txt) and it's not that clear.
I know for instance the rule:
RRULE FREQ=MONTHLY;INTERVAL=1;BYDAY=TH,FR,WE;BYSETPOS=10,11,12,7,8,9,1,2,3,4,5,6
Is for Wed, Thur, Friday on the 1st,2nd,3rd and 4th week of the month.
or
RRULE FREQ=MONTHLY;INTERVAL=1;BYDAY=TU,MO;BYSETPOS=3,4,5,6;
Is for Monday and Tuesday on the 2nd and 3rd week of the month.
or
RRULE FREQ=MONTHLY;INTERVAL=1;BYDAY=TH,WE;BYSETPOS=-1,-2
Is for Wed and Thursday on the last week of the month.
I generated these via another program, but am not sure how it actually generated them.
Thus the problem I am having is understanding how the BYSETPOS describes reoccurrence weeks for a month. The final goal is to be able to parse a RRULE such as the above and display at like so:
For: RRULE FREQ=MONTHLY;INTERVAL=1;BYDAY=TH,FR,WE;BYSETPOS=10,11,12,7,8,9,1,2,3,4,5,6
Show: Thur,Friday,Wed on week:1,2,3,4
For: RRULE FREQ=MONTHLY;INTERVAL=1;BYDAY=TU,MO;BYSETPOS=3,4,5,6;
Show: Tues, Monday on week:2,3
For: RRULE FREQ=MONTHLY;INTERVAL=1;BYDAY=TH,WE;BYSETPOS=-1,-2
Show: Whu,Wed on last week
The best solution would be a string in objective-c, but I can figure it out if it's another C like language. Even just a explanation of how BYSETPOS with BYDAY works would be great.
Thus the problem I am having is understanding how the BYSETPOS describes reoccurrence weeks for a month.
BYSETPOS does not represent weeks but simply the nth instance once you have calculated the instances corresponding to the remaining of the rule.
For example, FREQ=MONTHLY;INTERVAL=1;BYDAY=TU,MO corresponds to every mondays and tuesdays of the month, every month. So for each month, you first calculate a set (e.g. 9 entries if you take July 2014). Then BYSETPOS gives you the "indexes" into the set that you should keep, -1,-2 meaning the last 2 entries into the set.
Continuing with the July 2014 example, the base rule will return the following set: (1st, 7th, 8th, 14th, 15th, 21st, 22nd, 28th, 29th of July). Given a BYSETPOS=1,2,-1,-2, we will keep 1st, 7th, 28th, 29th of July.
You want to look at https://www.rfc-editor.org/rfc/rfc5545 which obsoletes RFC2245 and has a more detailed description of recurrence rules.
Good explanation Arnaud. Helped me get my own head around it.
Because this is such an unusual concept for myself and others to grasp, I have copied a wiki page I created for myself along with a short php script I've created to clearly understand by demonstration how it works.
BYSETPOS is not a rule but something that limits an existing rrule.
For instance, let's say you have an RRULE for an event that occurs twice a month on Mon and Tue forever like this:
FREQ=MONTHLY;INTERVAL=1;BYDAY=MO,TU
Now let take the example Arnaud provided above and focus only on the month of July as an example.
July 1st is the first Wed
July 7th is the following Tue followed by the 8th being the next Wed and so on.
Our RRULE above would have the event falling on July 1st, 7th, 8th, 14th, 15th, 21st, 22nd, 28th and 29th
Now let us append a BYSETPOS limiter.
FREQ=MONTHLY;INTERVAL=1;BYDAY=MO,TU;BYSETPOS=1,2,-1,-2
What is this saying exactly?
It is saying OK, we know your rule would have the event falling on July 1st, 7th, 8th, 14th, 15th, 21st, 22nd, 28th and 29th. However, we only want display the 1st, 2nd instances (1,2) of the event as well as the last (-1) and the 2nd to the last (-2).
BYSETPOS says to show ONLY those instances that are in the BYSETPOS limiter.
So if you took the array of days $moDays Array(1,7,8,14,15,21,22,28,29) and parsed it with the BYSETPOS limiter $bspLimiter=Array(1,2,-1,-2) it would look likethe following:
<?php
// 9 event days - limiting the events displayed based on the BYSETPOS limiter
$moDays = array(1,7,8,14,15,21,22,28,29);
$bspLimiter = array(1,2,-1,-2);
$keepers = [];
for($b=0;$b<count($bspLimiter);$b++){
if($bspLimiter[$b] < 0){
echo '$bspLimiter[$b] is negative value ('.$bspLimiter[$b].') so getting from back of array<br>';
$limiter=count($moDays)+$bspLimiter[$b];
$keeper=$moDays[$limiter];
$keepers[]=$keeper;
} else {
# accounting for index
$limiter = $bspLimiter[$b]-1;
$keeper=$moDays[$limiter];
$keepers[]=$keeper;
}
echo '<b>keeping '.$keeper."</b><Br>";
}
echo "<hr>";
asort($keepers);
echo $keepers=str_replace("'","",implode("', '", $keepers));
?>

Calculate end date based on # of days and start date

I am working on script where users can make certain type of orders. Now when users make an order they can choose how long they wont it to last in # of days. Once the order is placed I need to approve their order and that approval date is recorded inside my database. Now what I need is to show inside their user panel how much days their package will last since the day of my approval. So for example if I approved their order September 08, 2013 and they choosed for the order to last 7 days, I wont them to see inside they panel for every next day they login how much days they have left, so 7days, 6days, 5days, etc... all the way to "0 Days" when they come to their panel on September 16, 2013.
I have following variables for those two values:
$row_ordersResults['date'] - the date I approved the order
$row_ordersResults['drip_feed'] - # of days they wont for their order to last
I did tried to lots of combinations by myself but I am totally stuck with this and cant make it work.
Thanks for help!
The libraries at momentjs.com is pretty cool. But if you just wanted something simple to calculate the "date difference" between two time values, there is a relatively simple way to do it. I assume you wanted it done in Javascript.
All you need to do is to clear out the hour/minute/second/millisecond fields of the two dates, calculate their differences in days. Put the script below in any web browser and you'll see how it works.
<script>
function foo() {
var d1 = new Date(2013, 8, 12, 13, 40, 1, 333); // any date value, last 4 params can be anything
var d2 = new Date(2013, 9, 3, 11, 42, 32, 533);
d1.setHours(0); d1.setMinutes(0); d1.setSeconds(0); d1.setMilliseconds(0);
d2.setHours(0); d2.setMinutes(0); d2.setSeconds(0); d2.setMilliseconds(0);
daysLeft = (d2.getTime() - d1.getTime())/(24*60*60*1000);
alert('Dear customer, there is(are) ' + daysLeft + ' day(s) left on your order!' );
}
</script>
Show Remaining Days on Order
EDIT: adding PHP version
<?php
$d1 = New DateTime('2013-08-28 06:25:00');
$d2 = new DateTime(); // now
$drip = 55;
$interval = $d2->diff($d1); // time difference
$days_left = $drip - $interval->format('%a'); // in days, subtract from drip
echo "There are $days_left days left\n";
?>
I hope I don't get marked down for not suggesting a specific answer, but time and date calculations are very tedious and JavaScript's Date() provides limited options. So rather than offer some ugly code, I suggest you take a look at moment.js at momentjs.com. Once you attach the script to your pages, you can easily manage all kind of date formats, and set up a function that will allow you to do math on dates and automatically generate your date ranges - it will even let you format them in to user friendly formats like "in 3 days", which I think is what you want. If your app has anything to do with time, and most do, I can't recommend Moment highly enough.

How to get charges(transactions) details in Stripe based on date range

I wanted to get a list of charges(Transactions) based on date range I specify, ie all transactions between my specified Start date and End date.
But in CHARGES API, I can not see any Start date nor End Date arguments.
How can I get this?
Had a chat with Stripe staffs through online chat, and found that there is a way to get list of charges based on date range.
Stripe Charges API actually has some argument that are not yet listed in their documentation.
Arguments like created[lte] and created[gte] with Unix timestamp can be used, just like Events API call.
EG: https://api.stripe.com/v1/charges?created[gte]=1362171974&created[lte]=1362517574
Try this one. It's working for me
$pcharges = Charge::all(
array(
'limit' => 100,
'created' => array(
'gte' => strtotime('-15 day'),
'lte' => strtotime('-1 day')
)
)
);
This will return last 15 days data excluding today's transaction. You can set your custom date range as per your requirement.
Here's a Ruby based hack
Stripe.api_key = ENV['STRIPE_SECRET']
stripe_charges = []
first_charge = Stripe::Charge.all(limit: 1).data[0].id
charge_index = first_charge
*a lot of*.times do
new_charges = Stripe::Charge.all(limit: 100, starting_after: charge_index).data
stripe_charges << new_charges
charge_index = new_charges.last.id
stripe_charges.flatten!
end
Was looking in to it today and here is what i found
https://stripe.com/docs/api/curl#list_charges
curl https://api.stripe.com/v1/charges?limit=3 \
-u sk_test_BQokikJOvBiI2HlWgH4olfQ2:
This is stripes curl example there are more examples on their website.
-James Harrington
In case anyone is using Ruby on Rails and is looking for a solution to list out all refunds that's been created after a Unix timestamp, using the created.gte syntax, here's a working example for me that I got from Stripe Support.
Stripe::Refund.list({limit: 100, created: {gte: 1614045880}})
You can change that Unix timestamp to fit your situation.
Resources: Stripe API Reference, List all refunds and Stripe Support
To get particular date data code is like
$mydata= \Stripe\Charge::all(array('limit'=>50,'starting_after'=>null ,"created" => array("gt" => strtotime("2020-02-17"),"lt" => strtotime("2020-02-19"))));
print_r($mydata);
It will give you data of 2020-02-18 with limit 50, If you want more record add last charge id in starting_after parameter