Moment timezone and Ionic2 datepicker - ionic2

I am doing a simple test (i'm located in France) using moment and moment-timezone (with moment Angular2 libraries).
I'm not succeeding at getting logical results despite whats in the docs.
let timezone = moment.tz.guess();
console.log(timezone); // ok: Europe/Paris
let now = moment();
let nowFr = now.tz(timezone); // docs: should convert to time zone
// both display UTC format (13pm instead of 15pm local time)
console.log(now.toISOString());
console.log(nowFr.toISOString());
// first show 13pm, second 15pm
// this works, but i'm supposed to be passing ISO string to Ionic2 date picker !!
console.log(now.format());
console.log(nowFr.format());

Related

How to get local time of different timezone in Postman?

I want to get local time of Rome time zone. Didn't find any details on how to use moment sandbox built-in library in postman documentation here postman_sandbox_api_reference
what I have tried so far
var moment = require('moment');
console.log(moment().tz(environment.TimeZone).format());
error it throws - TypeError | moment(...).tz is not a function
another attempt-
var moment = require('moment-timezone');
console.log(moment().tz(environment.TimeZone).format());
error it throws - Error | Cannot find module 'moment-timezone'
Where I'm going wrong? can anyone point me in right direction.
Thanks
Postman only has the moment library built-in and not moment-timezone.
If what you're doing isn't part of the moment docs, it's not going to work.
https://momentjs.com/docs/
As a workaround to get the data, you could use a simple 3rd party API.
Making a request to this endpoint would get you some timezone data that you could use.
http://worldtimeapi.org/api/timezone/Europe/Rome
This could be added to the pm.sendRequest() in the pre-request script to fetch the data you require and use this in another request.
pm.sendRequest("http://worldtimeapi.org/api/timezone/Europe/Rome", function (err, res) {
pm.globals.set("localTimeRome", res.json().datetime);
});
Actually, you can write a simple function to get local time in other time zones only with moment:
const moment = require('moment');
const TimeZoneUTCOffsetMapping = {
'America/Chicago': -6,
'Europe/Rome': 2,
'Asia/Shanghai': 8,
...
};
const LocalUTCOffset = 8;
function getMomentDisplayInTimeZone(momentObj, timeZone) {
let timeZoneUTCOffset = TimeZoneUTCOffsetMapping[timeZone];
if (timeZoneUTCOffset === undefined) {
throw new Error('No time zone matched');
}
return momentObj.add(timeZoneUTCOffset - LocalUTCOffset, 'hour').format('YYYY-MM-DDTkk:mm:ss');
}
console.log(getMomentDisplayInTimeZone(moment(), 'Europe/Rome'));

Show Current Date Time in field in alpaca automatically

I am using alpaca framework. I have date time type, when I click on it only I can able to select the DateTime, I want this to be filled automatically with current date time when it gets focus or when page loaded.
Any suggestions please.
You can use the "data" object in alpaca config to set the date field default value to current date:
"data": { "myDateField": new Date() // or you can use moment } }
You can also set the date in the postRender function like this:
"postRender": function(control) {
var date = control.childrenByPropertyId["date"];
var currentDateTime = moment().format("MM/DD/YYYY HH:mm:ss")
date.setValue(currentDateTime);
}
Here's a working fiddle for that.

Regex is working in regex101.com but not in google scripts

The problem:
I had a similar problem to this thread - my Regex works like a charm in regex101, but returns null in google scripts.
I'm trying to return the next line on a number of items:
Confirmation code
Check-in
Checout
Payout
Number of Guest
Payout
Here is the data I am searching in:
New booking confirmed!Jake arrives Oct 22
Send a message to confirm check-in details or welcome Jake.
Jake Flake
Phoenix, California, United States
Airbnb member since 2015
Send Jake a message:
https://www.airbnb.com/z/q/;laskdf;lksjdf
The Getaway
https://www.airbnb.com/manage-listing/asdflkjsdf;lkajsfd
Trip details
Check-in
Sun, Oct 22
Anytime after 4PM
Checkout
Thu, Oct 26
11AM
Guests
13
Confirmation code
H7XS0SA8
View itinerary
https://www.airbnb.com/reservation/itinerary?code=aasdfasdf
Payment
$275.50 x 4 nights
$1102.00
Cleaning Fees
$180.00
Guest Pays
$1282.00
Airbnb Fees
-$38.46
You earn
$1243.54
On the day after your guest checks in, the payment method you supplied will be credited. For details, see your transaction history.
Your guest paid $161.15 in Occupancy Taxes. Airbnb remits these taxes on your behalf.
Get ready for Jake’s arrival
Provide Directions
Confirm that your guest knows how to get to your place.
Tidy Up
Clean up all shared spaces. Make sure your guest has clean linens and towels.
Customer Support
Visit Help Center
https://www.airbnb.com/help?eal_exp=asdfasdf
Contact Airbnb
https://www.airbnb.com/help/contact_us?eal_exp=asdfasdf
Thanks,
The Airbnb Team
Email preferences
https://www.airbnb.com/users/notifications?eal_exp=asdfasdf
Airbnb
My code that works:
function getNumberofGuests(message_body) {
var num_guests = message_body.match("Guests[\r\n]+([^\r\n]+)")[1];
Logger.log("num_guests: " + num_guests);
return num_guests;
}
Logs -- num_guests: 13
The same code in a similar senario that doesn't work:
function getReservationID(message_body) {
var reservationID = message_body.match("Confirmation\scode[\r\n][^\r\n]+")[1];
Logger.log("reservationID: " + reservationID);
return reservationID;
Logs -- reservationID: null
PS
The formatting of the body in this display is off for some reason, and I tried for 30 minutes but still couldn't fix it. In the message_body, it should be a new line after "Check-in", "Checkout", "Guests", "Confirmation code", etc. - there is a new line after every element that is currently showing a space.
I also tried the space character regex, and still got null:
var regExp = new RegExp("Confirmation\scode[\s]^[^\s]+", 'g')
After taking a look at the code and trying it out, you're getting the null because of what you changed in the match method. The reason why num_guests works is because that it's set up in a way that looks for the word "Guests" and the next line is the result from the array (notice the [1] on the end of the line). That same concept/regex works for the confirmation code portion as well, but you put in the "\s" and changed the order of some parentheses. Since the search code is in double quotes, you don't need the "\s". Basically, you have "Confirmation\scode" when you want "Confirmation code". Although it works in regex101, trying in the Google Apps Script environment will produce actual results.
I loaded the data into a file and then loaded the file into variable dt in the following code:
function getMyData()
{
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet()
var dt=myUtilities.loadFile('regex.txt');
var guests = dt.match(/^Guests (\d+)/m)[1];
var cf=dt.match(/^Confirmation code ([0-9A-Z]+)/m)[1];
var ui=HtmlService.createHtmlOutput(dt).append(Utilities.formatString('<br /><strong>Matches:</strong><br />Guests=%s<br />Confirmation Code=%s',guests,cf));
SpreadsheetApp.getUi().showModelessDialog(ui, 'Input Data & Extracted Parameters');
}
After playing with the regexs for a while I got this output which includes a copy of the data:
(The m flag is for multiline).
I missed some of the data the first time around.
Here's the new code with some of your additional parameters:
function getMyData()
{
var ss=SpreadsheetApp.getActive();
var sh=ss.getActiveSheet()
var dt=myUtilities.loadFile('regex.txt');
var guests = dt.match(/^Guests (\d+)/m)[1];
var cf=dt.match(/^Confirmation code ([0-9A-Z]+)/m)[1];
var chout=dt.match(/^Checkout (.*)$/m)[1];
var chin=dt.match(/^Trip details (.*)$/m)[1];
var payout=dt.match(/Guest Pays ([$.0-9]+)/m)[1];
var ui=HtmlService.createHtmlOutput(dt).append(Utilities.formatString('<br /><strong>Matches:</strong><br />Guests=%s<br />Confirmation Code=%s<br />Checkout=%s<br />Checkin=%s<br />Payout=%s',guests,cf,chout,chin,payout)).setWidth(1200);
SpreadsheetApp.getUi().showModelessDialog(ui, 'Input Data and Extracted Parameters');
}
And here's the output:
I'm guessing that you can figure out how to get the rest of them yourself.

IBM Watson Alchemy news iOS SDK Swift

The IBM Watson iOS SDK using the Alchemy News service on Bluemix returns a string result which requires parsing to pull out the fields like url and cleaned title. ref: https://github.com/watson-developer-cloud/swift-sdk
I pull the string into an array and parse it in swift3 using some string methods but this is pretty ordinary and can produce unpredictable results
Is there a more elegant approach where I can access specific fields, like the url and cleaned title which I am passing to a UITableViewCell to select and segue to the url link.
sample code:
let alchemyDataNews = AlchemyDataNews(apiKey: apiKey)
let failure = { (error: Error) in print(error) }
let start = "now-14d" // 7 day ago
let end = "now" // today
let query = ["count": "15",
"dedup": "true",
"q.enriched.url.title": "[IBM]",
"return": "enriched.url.url,enriched.url.title" "enriched.url.title,enriched.url.entities.entity.text,enriched.url.entities.entity.type"]
Also I have noticed the search string [IBM] has a prefix of 0, i.e. 0[IBM] and have also seen an "A". What do these prefixes mean and where are they documented
Here is one way you can access the fields from a returned payload.
alchemyDataNews.getNews(from: "now-4d", to: "now", query: queryDict, failure: failWithError) { news in
for doc in (news.result?.docs)! {
var cleanedTitle = doc.source?.enriched?.url?.cleanedTitle
var author = doc.source?.enriched?.url?.author
var title = doc.source?.enriched?.url?.title
}}
Also, here is a nice API reference link for alchemy data which contains all of the request parameters and filters.
https://www.ibm.com/watson/developercloud/alchemydata-news/api/v1/

Default time set in chageDate function

I am using bootstrap datetimepicker. If I choose any date means, its automatically taking current time(Hours and minutes). How to set the default time in bootstrap datetimepicker. Here, I want to set the default time inside of the "changeDate" function. I am using the following code,
$('#datetimepicker'+rowIndx).datetimepicker({
format : "dd/MM/yyyy hh:mm",
pickSeconds:false,
}).on("show",function(e) {
$('#datetimepicker'+rowIndx).datetimepicker("setDate", "");
}).on('changeDate', function(e) {
});
Please explain me, how to set default "time" in "changeDate" function.
It could be done by the next code:
$('#datetimepicker'+rowIndx).data("DateTimePicker").setDate(new Date());
Check the working fiddle