I understand how to access an object's modification date using the Last Modified On attribute. Is there any hidden / undocumented way to access the modification time with DOORS 9.5? In my case, I want to identify changes since a certain daytime, thus the date is not precise enough.
According to this post at the IBM forum, the attribute was supposed to return date and time. However, the output of this statement:
Date lastModified = obj."Last Modified On"
print "dateAndTime = " (dateAndTime(lastModified)) "\tlastModified = " lastModified "\tdateOnly = " dateOnly(lastModified) "\n"
is in my case
dateAndTime = 08/04/14 00:00:00 lastModified = 04 August 2014 dateOnly = 04 August 2014
and I guess that this means that the change time was not provided (correctly).
Section "History" of the DXL manual describes the function Date lastModifiedTime({Module|Object|Link}) which provides the desired time.
Unfortunately the Last Modified On attribute is only storing the date without a time. In order to get the time of the last modification, you would need to step through the history records on the object and get the time from the last record. This will also be an issue because any object that hasn't changed since the baseline will have no history records against it.
Related
I am working with Breeze and running into some date/time issues.
I have a field in a form, with a date time picker, that is returning a value of 07/20/2018 14:00. For this example, assume I am in CST timezone (GMT -0500). What I would like to do is pass that value to my Breeze entity manager and have it saved in my database correctly. I get the date into a variable:
dateVariable = ctx.ChosenTime;
This works and puts a value of 07/20/2018 14:00 into the variable dateVariable.
I create a new entity:
var newEntity = entityManager.createEntity('Test Entity', {Date: dateVariable};
And when I debug and check the value of newEntity, it has a property called Date with the proper value. However, once I call entityManager.SaveChanges(), and then get the returned value back, it is displayed as 07/20/2018 19:00. Since Breeze is handling the display value (via data binding), I am not sure why this is happening. Any advice would be appreciated. Thanks
When the JSON response comes from the server, if the date string does not have a timezone specifier, Breeze assumes it is in UTC and puts a "Z" on the end before parsing. So it converts your local time to UTC after the round-trip to the server. The solutions are:
Change your server-side property to DateTimeOffset or similar data type that preserves the timezone of a date. This way the returned date will have a time zone.
Tell Breeze not to add the "Z" and just interpret the date in local time. See this SO answer for more information.
I am pulling a Date from a database, reassigning it as a TextField, and then toString() it, but the date comes out "Thurs 0900 OCT 12 2015" when all I need is MM/DD/YYYY format. How do I change the format?
Date myDatabaseDate = someDBGetMethod();
TextField myDateTF = new TextField()
myDateTF.setCaption("My date is: ");
myDateTF.setValue(myDatabaseDate).toString());
myDateTF.setReadOnly(true);
FormLayout fLayout = new FormLayout();
addComponent(fLayout);
fLayout.addComponent(myDateTF);
What's happening: Thu Oct 22 12:19:04 CDT 2015
What I want: 22/10/2015
Thank you in advance!
Examples make the most sense to me as I am very new to vaadin.
Vaadin Not The Problem
If trying to display a String representation of a date-time object, then Vaadin is not a part of the problem. Vaadin offers a widget, DateField, for the user to pick a date-time value. You do not need that widget for simply displaying the string representation. For display, use a TextField as you described in the Question.
So the problem is how to generate that String representation.
First be aware that Java includes two classes named "Date":
java.util.Date
java.sql.Date
Confusingly, they are not parallel. The util one is a date plus a time-of-day in UTC. The sql one is meant to represent a date-only, but is poorly designed; as a hack it subclasses the util one but alters the time-of-day to be 00:00:00.000. These old date-time classes in early Java are a bad mess.
From a database you should be receiving the latter, java.sql.Date for a date-only stored value. If you were storing date-time values, then you should be getting java.sql.Timestamp objects from your JDBC driver.
java.time LocalDate
As java.sql.Date is one of the old clunky date-time classes bundled with early Java, we should convert to the new classes found in the java.time framework built into Java 8 and later. See Tutorial.
For a date-only value, java.time offers the LocalDate class. The "Local" in the name refers to any locality rather than a particular locality. It represents the vague idea of a date, but is not tied to the timeline. A date starts earlier in Paris than in Montréal, for example. If you care about exact moments on the timeline, you would be using java.sql.Timestamp rather than java.sql.Date.
Converting from java.sql.Date to java.time.LocalDate is an easy one-liner, as a conversion method is provided for you.
LocalDate localDate = myJavaSqlDate.toLocalDate();
Going the other way is just as easy, when storing data into the database.
java.sql.Date myJavaSqlDate = java.sql.Date.valueOf( localDate );
With a LocalDate in hand, you can call on the java.time.format package to format a string localized for easy reading by the user. Specify the Locale expected by the user.
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate( FormatStyle.FULL ).withLocale( Locale.CANADA_FRENCH );
String output = localDate.format( formatter );
Example output:
dimanche 1 novembre 2015
ZonedDateTime
Let’s consider if you did get a java.sql.Timestamp rather than java.sql.Date.
We can convert from a java.sql.Timestamp to a Instant, a moment on the timeline in UTC.
Instant instant = myTimestamp.toInstant();
Next, assign a time zone.
ZoneId zoneId = ZoneId.of( "America/Montreal" );
ZonedDateTime zdt = ZonedDateTime.ofInstant( instant , zoneId);
We use the java.time.format package to create the String representation. Note the chained calls, the second one setting a specific Locale. If not specified, your JVM’s current default Locale is implicitly applied. Better to be explicit.
DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime ( FormatStyle.FULL ).withLocale ( Locale.CANADA_FRENCH );
String output = zdt.format ( formatter );
Example output:
dimanche 1 novembre 2015 2 h 24 EST
java.util.date object does not contain any information how to present himself as String. That's because in different locations communities writes dates in different ways. So Java separates operations on dates from printing them out on the screen.
What you are missing in your code is a DateFormat.
Date myDatabaseDate = new Date(2014,10,10);
DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, Locale.UK);
TextField myDateTF = new TextField();
myDateTF.setCaption("My date is: ");
myDateTF.setValue(format.format(myDatabaseDate));
myDateTF.setReadOnly(true);
layout.addComponent(myDateTF);
I would strongly encourage you however to use Java 8 Dates API since Java 7 Dates API is a total mess. You can read more about that here What's wrong with Java Date & Time API?
trying to pass a datetime object that has already been converted to UTC by momentjs to my MVC controller. I'm using a kendo datetimepicker, and for some reason, moment.utc just will not send the controller the value that i want. For example, i type in '9/17/2015 12:00 AM' into my kendo datetimepicker. I get this value like:
var start = $("#startTime").val();
which gives me "9/17/2015 12:00 AM" . great. then i convert this to a date object:
var t1 = new Date(start);
which reads as Thu Sep 17 2015 00:00:00 GMT-0700 (Pacific Daylight Time) {} . Still looking good. Next i try to convert to UTC with moment using:
var t2 = moment.utc(t1);
this gives me
dt {_isAMomentObject: true, _i: Thu Sep 17 2015 00:00:00 GMT-0700 (Pacific Daylight Time), _isUTC: true, _locale: fu, _d: Thu Sep 17 2015 00:00:0...
did NOT convert to utc. instead of converting all it seemed to do was take a date object and let me tell it 'hey, this is utc' and it said 'ok' (by flagging _isUTC:true), even though it's still saving the GMT value in there
even if i decided to make a moment object first, and then run UTC on it? it still comes out the same:
var t2 = moment(t1);
var t3 = moment.utc(t2);
So either of those values, if i run .format() on them (which is what i need to pass to my controller), i always get "2015-09-17T07:00:00+00:00", which is NOT the UTC time. It's the exact time i typed in. What am i doing wrong here?
A few things:
Don't even look at the fields prefixed with underscores. They're part of the internal design of moment.js, and not meant for direct consumption. In many cases, several of the fields have to be combined to get the correct results. This is accounted for in the functions of the public API, such as format.
Don't rely on the Date object to do your parsing. Results can be inconsistent across browsers. Moment has its own parser, which you can use like this:
moment("9/17/2015 12:00 AM","M/D/YYYY h:mm A")
However, in your particular case, you actually don't need to parse any string at all. You said you're using Kendo's DateTimePicker control, so you should use the value function, which already returns a Date object.
Moment has two different functions for working with UTC.
moment.utc(value) - interprets values in terms of UTC
m.utc() - where m is any moment instance, converts the value to UTC
Note that the second one it mutates the existing instance by switching it from "local mode" to "UTC mode". It also returns the instance if you want to chain functions, but it does modify the original instance as well.
You can use format after converting to UTC if you want the output to show the +00:00 offset. However, if you want to show Z (which is usually preferred), you you can just call .toISOString() without explicitly going to UTC first - since that function always outputs UTC.
Additionally, most modern browsers already support .toISOString() directly on the Date object, so unless you're targeting older browsers, you might not need moment at all.
You said "2015-09-17T07:00:00+00:00" was not the UTC time, but actually it is. You started with 00:00 in UTC-7, which is equivalent to 7:00 in UTC+0. So despite jumping through several unnecessary steps, moment still got it right in the end - at least with t3.
You can simplify your code with any of these:
var picker = $("#startTime").data().kendoDateTimePicker;
var dt = picker.value(); // dt is a Date object
var m = moment(dt); // m is a moment object
m.utc(); // m has been converted to UTC
var s = m.format(); // ex: "2015-09-17T07:00:00+00:00"
Or...
var picker = $("#startTime").data().kendoDateTimePicker;
var dt = picker.value(); // dt is a Date object
var m = moment(dt); // m is a moment object
var s = m.toISOString(); // ex: "2015-09-17T07:00:00Z"
Or...
var picker = $("#startTime").data().kendoDateTimePicker;
var dt = picker.value(); // dt is a Date object
var s = dt.toISOString(); // ex: "2015-09-17T07:00:00Z" (requires browser support)
Background: I'm building an app with Angular JS as web interface and Rails API. The problem I am having is passing a date from Angular to Rails.
Issue: I have a form with a Date of Birth date field, when a user inputs his DOB say March 1st, 1985, Angular interprets it as 1985-03-01 00:00 +0800 (if you're in Hong Kong or Singapore) and sends a request to Rails. The first thing Rails does with it is to convert it to UTC, which means the datetime is now 1985-02-28 16:00 UTC. Therefore, when the date is saved to the database date column, it becomes Feb 28, 1985.
Solution for now: What I'm doing now is on Angular side, I get the Timezone offset hours and add it to the date, so instead of 1985-03-01 00:00 +0800, it is now 1985-03-01 08:00 +0800. When Rails get it, it converts to 1985-03-01 00:00 UTC and so saves the correct date to db. However, I believe this is a better alternative to tackle this issue.
Thinking about parsing just the date in Rails, yet the params[:dob] I see is already UTC by the time I get it. Would love to know if there is a better practice than my current solution. Thank you for any comment and feedback.
This problem is actually quite common, and stems from two separate but related issues:
The JavaScript Date object is misnamed. It's really a date + time object.
The JavaScript Date object always takes on the characteristics of the time zone for the environment in which it is running in.
For a date-only value like date-of-birth, the best solution to this problem is to not send a full timestamp to your server. Send just the date portion instead.
First, add 12 hours to the time, to use noon instead of midnight. This is to avoid issues with daylight saving time in time zones like Brazil, where the transition occurs right at midnight. (Otherwise, you may run into edge cases where the DOB comes out a day early.)
Then output the date portion of the value, as a string in ISO format (YYYY-MM-DD).
Example:
var dt = // whatever Date object you get from the control
dt.setHours(dt.getHours() + 12); // adjust to noon
var pad = function(n) { return (n < 10 ? '0' : '') + n; }
var dob = dt.getFullYear() + '-' + pad(dt.getMonth()+1) + '-' + pad(dt.getDate());
Another common way to do this is:
var dt = // whatever Date object you get from the control
dt.setHours(dt.getHours() + 12); // adjust to noon
dt.setMinutes(dt.getMinutes() - dt.getTimezoneOffset()); // adjust for the time zone
var dob = dt.toISOString().substring(0,10); // just get the date portion
On the Rails side of things, use a Date object instead of a DateTime. Unlike JavaScript, the Rails Date object is a date-only object - which is perfect for a date-of-birth.
My task: I am going to run a contest world wide at my website. A problem setter will set problems from a specific area of the world setting a time and date of starting time of the contest. I have to show that time correctly all over the world so the the contest starts at a time everywhere of the world.
My Idea : I planed to get the time from the problem setter of his time zone using server site language like php time(), & will store to database converting to timezone= zero (0). And who are going to attend the contest I'll just add hour(s) of that time zone with my database time.
Need help: I have no Idea how to convert that timestamps to timezone 'zero', even how can I get the ±hour(s) of current timezone?
Thank you...
Step 1:
Let the user choose his timezone. You could fill a dropdown with values from this site: http://php.net/manual/en/timezones.php
Step 2:
Convert the timezone to servertime
$timezone_client = new DateTimeZone('America/Denver');
$timezone_server = new DateTimeZone('Pacific/Nauru');
$datetime = new DateTime('2013-01-25 12:00:00', timezone_client);
$datetime->setTimezone($timezone_server);
echo $datetime->format('Y-m-d H:i:s');
Timezone 0 = "UTC" (sometimes called GMT)
Your system / language will have a Timezone class, which provides difference to GMT/UTC