When creating a new UILocalNotification and scheduling a notification, the time gets changed due to the timezone. I the date i set gets changed by UiLocalNotifcation to the timezone. which i don't want to happen
public static void RegisterLocalNotification(ServiceModel.Types.ParkingTicket parkingTicket)
{
if (parkingTicket == null || parkingTicket.ExpiringSoon) return;
var startDate = parkingTicket.UtcStart.ToLocalTime();
NSDate nsStartDate = startDate.AddMinutes(parkingTicket.Duration - 10).UtcDateTimeToNSDate();
var notification = new UILocalNotification
{
FireDate = nsStartDate,
TimeZone = null,
AlertAction = Resources.Strings.ExtendTicket,
AlertBody = string.Format
(Resources.Strings.FormattedExpiringMessage,
parkingTicket.TimeLeft.Description(false),
parkingTicket.Address,parkingTicket.Car.RegistrationNumber),
RepeatInterval = 0,
HasAction = true,
UserInfo = GetDictionaryFromParkingTicket(parkingTicket),
SoundName = UILocalNotification.DefaultSoundName,
ApplicationIconBadgeNumber = 1
};
UIApplication.SharedApplication.ScheduleLocalNotification(notification);
}
public static NSDate UtcDateTimeToNSDate(this DateTime utcDateTime)
{
var reference = new DateTime(2001, 1, 1, 0, 0, 0);
return NSDate.FromTimeIntervalSinceReferenceDate((utcDateTime - reference).TotalSeconds);
}
I have tried using TimeZone = NSTimeZone.LocalTimeZone.
You're converting a UTC date to a local date:
var startDate = parkingTicket.UtcStart.ToLocalTime ();
then you're treating the local date as a UTC date, thereby doing the conversion twice:
NSDate nsStartDate = startDate.AddMinutes(parkingTicket.Duration - 10).UtcDateTimeToNSDate();
Just do this instead:
var startDate = parkingTicket.UtcStart;
var nsStartDate = (NSDate) startDate.AddMinutes (parkingTicket.Duration - 10);
The explicit NSDate conversion will do the right thing.
Related
I am trying to print original first time and copy after the first time printing. I have created a custom field that stored the timestamp of first time printing. So, the template will check first time the field is empty so "original" is printed and the timestamp will stored to the field. Then, when the template is printed after the first time it will check the field, find that there is a content (The timestamp) so it will print copy on the printed template. everything is work fine, buttt when trying to access the advance template of the applied transaction (like: Bill or any) it show an error like below the code!!! What is the issue?
/**
*#NApiVersion 2.x
*#NScriptType UserEventScript
*/
define(['N/render','N/record'], function(render,record) {
function beforeLoad(context) {
var UserEventType = context.UserEventType;
var contextType = context.type;
var newRecord = context.newRecord;
var newRecordID= context.newRecord.id;
var currentDate = sysDate(); // returns the date
var currentTime = timestamp(); // returns the time stamp in HH:MM:SS
var currentDateAndTime = currentDate + ' ' + currentTime;
if (contextType == UserEventType.PRINT) {
var fieldId = 'custbody_first_print' // fieldId of your custom field / checkbox (or use a datetimestamp)
var isPrinted = newRecord.getValue({ fieldId: fieldId })
if (!isPrinted) {
var myRecord = record.load({id: newRecordID , type: newRecord.type}); // in the beforeLoad, editing the newRecord is not allowed, so you need to load the record first, edit and save.
myRecord.setValue({ fieldId: fieldId, value: currentDateAndTime })
myRecord.save();
}
}
}
function sysDate() {
var date = new Date();
var tdate = date.getDate();
var month = date.getMonth() + 1; // jan = 0
var year = date.getFullYear();
return currentDate = month + '/' + tdate + '/' + year;
}
function timestamp() {
var str = "";
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var meridian = "";
if (hours > 12) {
meridian += "pm";
} else {
meridian += "am";
}
if (hours > 12) {
hours = hours - 12;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
str += hours + ":" + minutes + ":" + seconds + " ";
return str + meridian;
}
return {
beforeLoad: beforeLoad,
};
});
The Error: Error during loading transaction for advanced printing Caused by: com.netsuite.suitescript.exception.NLServerSideScriptException: {"type":"error.SuiteScriptError","name":"SSS_MISSING_REQD_ARGUMENT","message":"load: Missing a required argument: id","stack":["createError(N/error)","beforeLoad(/SuiteScripts/Copy_Original.js:23)","createError(N/error)"],"cause":{"name":"SSS_MISSING_REQD_ARGUMENT","message":"load: Missing a required argument: id"},"id":"","notifyOff":false,"userFacing":true}
At first glance the base problem is that you are not passing a record ID to the record.load method.
A breakdown of the error:
What is the Error: "SSS_MISSING_REQD_ARGUMENT" (you are missing an argument that it needs in order to execute)
Where: "beforeLoad(/SuiteScripts/Copy_Original.js:23)" (the beforeLoad event in your suitescript Copy_Original, on line 23.)
What argument are you missing: "load: Missing a required argument: id" (after the : it tells you id)
I would change the names of your variables so they are different from the netsuite names. particularly newRecord, this will eliminate confusion and the possibility of you referencing a netsuite enum when you are trying to use your variable. (I believe that is what is happening here as I am able to get this to work on my record when using the following.)
function beforeLoad(context) {
var UserEventType = context.UserEventType;
var contextType = context.type;
var recObj= context.newRecord;
var recId= recObj.id;
var currentDate = sysDate(); // returns the date
var currentTime = timestamp(); // returns the time stamp in HH:MM:SS
var currentDateAndTime = currentDate + ' ' + currentTime;
if (contextType == UserEventType.PRINT) {
var fieldId = 'custbody_first_print' // fieldId of your custom field / checkbox (or use a datetimestamp)
var isPrinted = recObj.getValue({ fieldId: fieldId })
if (!isPrinted) {
var myRecord = record.load({id: recId, type: recObj.type}); // in the beforeLoad, editing the newRecord is not allowed, so you need to load the record first, edit and save.
myRecord.setValue({ fieldId: fieldId, value: currentDateAndTime })
myRecord.save();
}
It is worked now, check the sol. :
I should add && recId --->(context.newRecord.id)
if (contextType == UserEventType.PRINT && recId) {
var fieldId = 'custbody_first_print' // fieldId of your custom field / checkbox (or use a datetimestamp)
var isPrinted = recObj.getValue({ fieldId: fieldId })
if (!isPrinted) {
var myRecord = record.load({id: recId, type: recObj.type}); // in the beforeLoad, editing the newRecord is not allowed, so you need to load the record first, edit and save.
myRecord.setValue({ fieldId: fieldId, value: currentDateAndTime })
myRecord.save();
I have attribute names like startDate:2017-09-07 and endDate:2017-09-16 i want to reitrive data with this parameters and after writing response into the base i want to change this parameter i mean (startDate:2017-09-07 and endDate:2017-09-16 with 2017-09-17 and 2017-09-24) i tried this ecmascript code:
var OutputStreamCallback = Java.type("org.apache.nifi.processor.io.OutputStreamCallback");
var StandardCharsets = Java.type("java.nio.charset.StandardCharsets");
Date.prototype.isValid = function () {
return (Object.prototype.toString.call(this) === "[object Date]")
&& !isNaN(this.getTime());
};
function addDays(date, days) {
var result =new Date(date);
result.setDate(result.getDate() + days);
var dateFormated = result.toISOString().substr(0,10);
return formatDate(dateFormated);
}
function formatDate(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
return [year, month, day].join('-');
}
var startDate = startDate.getValue(),
endDate = endDate.getValue(),
parametr=parameter.getValue(),
count=count.getValue();
var flowFile = session.crete();
var param=8;
var endDate = addDays(end, param*count);
var startDate = formatDate(newStart);
flowFile = session.putAttribute(flowFile, 'startDate', startDate);
flowFile = session.putAttribute(flowFile, 'endDate', endDate);
session.transfer(flowFile, REL_SUCCESS)
but i don't know how can i make my code known when it should increase count in order to change endDate and startTdate manually and replace it with valid startDate and EndDate
is there any service or processor i can use to simplify this task?
I need add remind about appointment before end date, not start date.
This appointment's creation
private async void AddFavoriteTenderEndDateToCalendar(MyEvent event)
{
var appointment = new Appointment();
appointment.StartTime = new DateTimeOffset(event.StartDate);
appointment.Duration = event.EndDate - event.StartDate;
appointment.Subject = "blahblah";
appointment.Reminder = TimeSpan.FromDays(1);
var appointmentId = await AppointmentManager.ShowEditNewAppointmentAsync(appointment);
}
Appointment have not property EndTime and instead I calc duration appointment.Duration = event.EndDate - event.StartDate;
How can I add reminder before event.EndDate?
start time 13:00
End time 17:00
get all hours and put to array
output arrHrs = {"13","14","15","16","17"}
You have to try something like that
DateTime startTime = Convert.ToDateTime("01-01-2013 20:00");
DateTime endTime = Convert.ToDateTime("01-02-2013 02:00");
List<DateTime> list = new List<DateTime>();
list = Listhours(startTime, endTime);
Need to create a function like
private List<DateTime> Listhours(DateTime starttm, DateTime endtm)
{
var Listhour = new List<DateTime>();
DateTime startt = Convert.ToDateTime(starttm.ToString("MM/dd/yyyy HH:00:00"));
DateTime endd = Convert.ToDateTime(endtm.ToString("MM/dd/yyyy HH:00:00"));
for (double dblDate = startt.ToOADate();
dblDate <= endd.ToOADate();
dblDate += (1.0 / 24.0))
{
Listhour.Add(DateTime.FromOADate(dblDate));
}
return Listhour;
}
Hope it works.
var startTime = 13, endTime = 17;
var arrHrs = new List<int>();
while(startTime <= endTime)
{
arrHrs.Add(startTime++);
}
OR in an easier way
var startTime = 13, endTime = 17;
var arrHrs = Enumerable.Range(startTime, endTime);
How do I convert a DateTime from the local timezone returned by DateTime.Now to another timezone than Utc. On desktop we have the TimeZoneInfo.ConvertTimeBySystemTimeZoneId(), but it's not available on windows phone!
This java snippet shows roughtly what I want to do
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
TimeZone tz = TimeZone.getDefault();
format.setTimeZone(TimeZone.getTimeZone("GMT"));
str = format.format(new Date());
This is not possible to do using the system libraries as there is no way to create TimeZoneInfo objects other than local and utc. They have also sealed the class.
You can however use this simple library to enable conversion to non-local time zones.
https://nuget.org/packages/WinRTTimeZones
Use it like this:
using TimeZones;
public void ConvertTime()
{
// Get the time zone we want
var tz = TimeZoneService.FindSystemTimeZoneById("Central Standard Time");
var dt = new DateTime(1990, 7, 1, 12, 0, 0, DateTimeKind.Utc);
// This time will be central time
var local = tz.ConvertTime(dt);
}
When the DateTime is converted it is an easy exercise to format it as you want. I recommend to format the date in the local format (not the local timezone) to make easy for the user to understand the date.
Use it like this:
public String getNationTime(String Zone)
{
DateTime todayutc = DateTime.UtcNow;
string todaydate = todayutc.ToShortDateString();
string todaytime = todayutc.TimeOfDay.ToString().Split('.')[0];
Zone = Zone.Replace("GMT", "");
if (Zone.Length == 0)
return todaytime;
int zoneHour = int.Parse(Zone.Split(':')[0]);
int zoneMin = int.Parse(Zone.Split(':')[1]);
TimeSpan diff = new TimeSpan(zoneHour, zoneMin, 00);
todayutc = todayutc.Add(diff);
return todayutc.TimeOfDay.ToString().Split('.')[0];
}