Attempting to get the response from a TimeItem on my google form? - forms

When I use getResponse(), it returns a string that doesn't even have the AM or PM value. Thus I cannot use the Date and Time functions on the response. Does someone know how to get my timeItem response to save properly.
I do know that I need to create a Date object in order to use the date and time functions. That's not the problem.
var tester = Responses[3].getResponseForItem(Items[7]).getResponse();
It returns at string like "3:00" when I would rather it return something like "3:00PM"

The TimeItem class is defined on the 24-hour clock. I don't think they explicitly provide AM and PM tags. Note, this is also the case with DateTimeItems.
Documenation: TimeItem
If you want the string to be 3:00PM/AM instead of 3:00, write a short conditional statement.
Something like:
if(timeItem > 12:00 AND timeItem < 23){
tester = tester + "PM";
} else {
tester = tester + "AM";
}

Related

cant translate text with value using GETX in flutter

the problem is that the text has value which declares the day before the text
so idk how to translate this text that includes value.
untilEventDay =
'${pDate.difference(DateTime.now()).inDays},days/ until event day'
.tr;
in translation page :
,days/ until next event day': 'ڕؤژ ماوه‌/ تاوه‌كو ئیڤێنتی داهاتوو',
you should separate the value's string from your translation
var eventDayCountDownTitle = '${pDate.difference(DateTime.now()).inDays}' + ',' + days/ until event day'.tr;
and if you need your day number to be in a specific language, you can use a map or a helper method. map solution would be something like this:
Map<String,String> englishToPersianNumber = {'1' : '۱'}
and then use it in your string :
englishToPersianNumber[pDate.difference(DateTime.now()).inDays.toString()]
Important: to have a cleaner code, you can create a helper method to generate your desired string, and call it in your text widget. the code would be more understandable that way. Also, you can add handle any conditions that may later be added to the string generator. like if it's the last day, write something else instead of 0 days remaining.
String eventDayCountDownTitle(int remainingDays) {
if(remainingDays == 0) return "Less than One day to the event".tr;
return '${remainingDays.toString}' + ',' + 'days/ until event day'.tr;
}
ps. your question's title is wrong, you should change it to what you're explaining in the caption

How to get dynamic and adaptive timestamp variable in Postman?

What i need to do is to generate few timestamps: timeNow, +1y ahead and +5years ahead and few other random dates. All that needs to happen in "Pre-request Script" for Postman API testing where rRequired format is: YYYY-MM-DDTHH:mm:ss.mssZ which in practice needs to like like 2021-02-24T12:05:35.423Z
First of all, when i'm trying to use {{$isoTimestamp}} dynamic variable it's not doing nothing which is already frustrating.
Secondly, I've managed to manually create a 'now' date and then concatenated that with 'Z' which already looks like ****
const moment = require('moment');
let eventDate = moment().format("YYYY-MM-DDTHH:mm:ss.ms);
let eventDateTime = eventDate + "Z";
So, that gives me time format (the string, actually) I wanted but does not provide any possibility to get those random dates, now+1year and now+5years. I'm kinda new to that so it's breaking my balls, really. Anyone has any idea, pretty please?
you can get dynamic variables in postman script sessions as :
console.log(pm.variables.replaceIn("{{$isoTimestamp}}"))
you should use replaceIn
Also to add something to date use something like:
if your start time is in the format YYYY-MM-DDTHH:MM:ss.SSSZ , then use:
const moment = require('moment');
if (pm.info.iteration === 0) {
pm.collectionVariables.set("startTime", moment.utc())
} else {
let measuredOnUtc = pm.collectionVariables.get("startTime")
measuredOnUtc = moment(measuredOnUtc)
pm.collectionVariables.set("startTime", measuredOnUtc.add(3, 'hours').utc())
}
if startime is in format DD-MM-YYYYTHH:MM:ss.SSS[Z] , then use:
const moment = require('moment');
if (pm.info.iteration === 0) {
pm.collectionVariables.set("startTime", moment.utc().format("DD-MM-YYYYTHH:MM:ss.SSS[Z]"))
} else {
let measuredOnUtc = pm.collectionVariables.get("startTime")
measuredOnUtc = moment(measuredOnUtc, "DD-MM-YYYYTHH:MM:ss.SSS[Z]")
pm.collectionVariables.set("startTime", measuredOnUtc.add(3, 'hours').format("DD-MM-YYYYTHH:MM:ss.SSS[Z]"))
}
THe request body should be :slight_smile:
{
bbla:bla,
"startTime": "{{startTime}}",
bbla:bla
}

Extracting only date from moment object

I am using ion2 calendar for creating a multidatepicker. Here I am using onSelect event emitter.
onSelect($event) {
console.log("onSelect event called");
console.log($event);
};
Here when I print '$event' the console output looks like this:
How to extract only date from this moment object in the format 'DD-MMMM-YYYY'?
Below one liner will give you desired output:
let formattedDate = moment($event[0].Moment._d).format('DD-MMMM-YYYY');
So your function will become
onSelect($event) {
let formattedDate = moment($event[0].Moment._d).format('DD-MMMM-YYYY');
console.log("onSelect event called");
console.log($event);
};
Note : As I can not debug your code so please check first that if $event[0].Moment._d is giving you highlighted date (_d: Wed May 16 ........) in your question.
In your case just use moment($event[0]).format('DD-MMMM-YYYY')
console.log(moment().format('DD-MMMM-YYYY'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.js"></script>

Add day to date with momentjs

I am trying to add a day to my date:
let createdDate = moment(new Date()).utc().format();
let expirationDate = moment(createdDate).add(1, 'd');
console.log(expirationDate);
However, this keeps returning an obscure object {_i: "2017-12-20T21:06:21+00:00", _f: "YYYY-MM-DDTHH:mm:ss Z", _l: undefined, _isUTC: false, _a: Array(7), …}
fiddle:
http://jsfiddle.net/rLjQx/4982/
Does anyone know what I might be doing wrong?
You are logging a moment object. As the Internal Properties guide states:
To print out the value of a Moment, use .format(), .toString() or .toISOString().
let createdDate = moment(new Date()).utc().format();
let expirationDate = moment(createdDate).add(1, 'd');
console.log(expirationDate.format());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
Please note that you can get the current date using moment() (no need to use new Date()) or moment.utc().
I will go with this one, simple works for me and I don't think you need other function to only add day in moment.
var yourPreviousDate = new Date();
var yourExpectedDate = moment(yourPreviousDate).add(1, 'd')._d;
The add method modifies the moment object. So when you log it, you're not getting an obscure object, you're getting the moment object you're working with. Are you expecting a formatted date? Then use format or some other method.
I agree with other answers just providing shortcut and different ways
You can do the format at the same time
moment().add(1,'d').format('YYYY-MM-DD');
or you can just format any date or date object
moment(result.StartDate).format('YYYY-MM-DD');

How to return a normal javascript date object?

Is it possible to return a javascript date object from this? I have an text input field with the calendar and want to return a standard date object from it's value... Is this possible?
Is this what you are looking for?
var date = '2016-06-12'; // Can be document.getElementById('myField').value that points to your date field.
var date_parts = date.split('-');
var date_obj = new Date(date_parts[0],date_parts[1],date_parts[2]);
console.log(date_obj);
You can also simply use
new Date(document.getElementById('myField').value)
and see if it works. The date function is smart enough to parse based on browser's locale. This should work for time as well. Eg. new Date('2016-06-12 04:15:30')