Convert moment.Duration into string - reactjs

I have a moment.Duration object which I need to convert to string format HH:mm:ss (without any timezone conversion). I know we can do like
foobar.hours + ":" + foobar.minutes + ":" + foobar.seconds
But honestly I was hoping to have a better solution that just string manipulations.

var now = moment()
var then = moment().subtract(3, 'hours').subtract(20, 'minutes')
const duration = now.subtract(then)
duration.format("HH:mm:ss")
>> 03:20:00

moment().format('HH:mm:ss');
if u have already moment object use like this
object.format('HH:mm:ss');

Related

String and state variable concatenation

I am creating url by concatenating constant string and state variables as follows :
var url={"http://localhost:3000/get-players/"+{this.state.city}+"/"+{this.state.sport}};
But I am getting error. Can someone tell me where am I making mistake.
You're string concatenation is incorrect, you could use string interpolation like this:
var url = `http://localhost:3000/get-players/${this.state.city}/${this.state.sport}`
If you don't want to use ES6 templating, do it the old way but remove the extra brackets ({}) around the variables.
var url = "http://localhost:3000/get-players/" + this.state.city + "/" + this.state.sport;
var url={"http://localhost:3000/get-players/"+{this.state.city}+"/"+{this.state.sport}};
{this.state.city} - is not string.
1: Correct variant for ES5:
var url="http://localhost:3000/get-players/" + this.state.city + "/" + this.state.sport;
this.state.city and this.state.sport should be declared and should be a type of string.
2: Correct variant for ES6
var url=`http://localhost:3000/get-players/${this.state.city}/${this.state.sport}`;

Add Single quotes where string contains comma in AngularJS

I have a string which contains values like
var string = A,B,C
Here I want to add single quote for each comma value, expected result should be as below
output = 'A','B','C'
My angular code is
var data = {
output : this.string.split("\',"),
}
which is giving result as
["A,B,C"]
Could anyone please help on this how can I get desired output.
I am understanding your code as
var string = "A,B,C"; // because string should be in this format.
and you just need to replace "\'," from your split function to "," which will give you an array like this
var out = string.split(",");
console.log(out);
[ 'A', 'B', 'C' ] // this is the output.
as split function searches for the given expression and split the string into array.
but if you just want to modify the string without making it in array then you can use the below trick
var out = "'" + string.replace(/,/g, "','") + "'";
console.log(out);
'A','B','C' // result as u mentioned and this is of string type.

How to add viewmodel object into cookies using angularjs 2

Im trying to add viewmodel objects into cookie using angularjs2. I have tried a lot, but didn't worked yet. I
private setCookie(name: string, value: any, expireDays: number, path: string = "") {
let d: Date = new Date();
d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000);
let expires: string = "expires=" + d.toUTCString();
document.cookie = name +`enter code here` "=" + value + "; " + expires + (path.length > 0 ? "; path=" + path : "");
}
I have tried like this,
this.setCookie("CookieConstant", ViewModel, 1);
When I'm checking cookie value in the browser I can see only [Object Object]. Can anyone help me. I'm new to angular 2
I think its not possible in angular 2, you better to set single value in the cookie, based on that value you can generate the results. Cookies is for setting small values, so its better to avoid setting viewmodel objects into cookies. Try to set single value.

Getting Google Event in Exchange Calendar with EWS

To get an event from an Exchange calendar by ICalUId, you can use the FindItem-operation, using the UId base64-encoded as value to the Extended property identified by
DistinguishedPropertySetId=Meeting, PropertyId=3 and PropertyType=Binary.
This works great for events that are created in the Exchange calendar, where ICalUIds look like the following: 040000008200E00074C5B7101A82E00800000000A7C552582821D1010000000000000000100000002550ED442EB2CF4287FD94D10A4F331D
However, this does not work when trying to get the event with a Google Calendar UId, which looks like the following:
tp90m1srk847n1oa4jtp9ofou0#google.com
Not even using the substring before #google.com works, sadly.
Is there a way to get Google Events in the Exchange Calendar with EWS?
The GlobalObjectId is generated from the UID in this case using the formula defined in https://msdn.microsoft.com/en-us/library/ee157690(v=exchg.80).aspx . So if all you have is the UID you will need to generate the GlobalObjectId to search using your own algorithm. eg
String UId = "k5abv4oduaidu8knel4088iq8c#google.com";
String Header = "040000008200E00074C5B7101A82E008";
String Padding = "0000000000000000000000000000000000000000";
String Prefix = "7643616C2D55696401000000";
String DataString = Prefix + BitConverter.ToString(ASCIIEncoding.ASCII.GetBytes(UId)).Replace("-", "") + "00";
String BigEndianlength = (DataString.Length / 2).ToString("X8");
String LittleEndianlength = BigEndianlength.Substring(6, 2) + BigEndianlength.Substring(4, 2) + BigEndianlength.Substring(2, 2) + BigEndianlength.Substring(0, 2);
String GlobalUidHex = Header + Padding + LittleEndianlength + DataString;
If you then conver the HexString to Base64 String that should work.
Cheers
glen

How can we convert an integer to string in AngularJs

How can we convert an integer to string in AngularJs, like parseInt() converts string to int.
I tried wit $parse, which itself is a wrong approach I think..
.toString() is available, or just add "" to the end of the int
var x = 3,
toString = x.toString(),
toConcat = x + "";
Angular is simply JavaScript at the core.
var x : number = 3;
var st : string = String(x);
console.log(st);

Resources