<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:34 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-357] Add a way to convert all DateTime values in a BsonDocument to local or universal time</title>
                <link>https://jira.mongodb.org/browse/CSHARP-357</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;When a BsonDocument is read back from the database all DateTime values are in UTC. It would be nice to have a helper method that walked the BsonDocument and converted all DateTime values to LocalTime. For example:&lt;/p&gt;

&lt;p&gt;var document = collection.FindOne(); // DateTimes are in UTC&lt;br/&gt;
document.ToLocalTime(); // converts any DateTime values found to LocalTime (in place)&lt;/p&gt;

&lt;p&gt;While less frequently useful, for symmetry there should probably be a ToUniversalTime method as well.&lt;/p&gt;

&lt;p&gt;An alternative to consider is whether there should be a mode (on the collection?) that would cause all DateTimes to be automatically converted to LocalTime without having to call a helper method. Although the helper method is by far simpler to implement.&lt;/p&gt;

&lt;p&gt;As an aside, I recommend that you always keep your DateTimes in UTC throughout, and only convert them to LocalTime when displaying them to the user. But I know that many developers prefer to just do a wholesale conversion to LocalTime after reading from the database, so this helper method would be attractive to them.&lt;/p&gt;</description>
                <environment></environment>
        <key id="25119">CSHARP-357</key>
            <summary>Add a way to convert all DateTime values in a BsonDocument to local or universal time</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="robert@mongodb.com">Robert Stam</reporter>
                        <labels>
                    </labels>
                <created>Fri, 18 Nov 2011 17:16:46 +0000</created>
                <updated>Thu, 2 Apr 2015 18:27:51 +0000</updated>
                            <resolved>Tue, 3 Jan 2012 22:09:18 +0000</resolved>
                                    <version>1.3</version>
                                    <fixVersion>1.4</fixVersion>
                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="162727" author="craiggwilson" created="Mon, 10 Sep 2012 22:32:11 +0000"  >&lt;p&gt;Based on this new ticket, we are removing support for the AsLocalTime and AsUniversalTime properties in version 2.0.&lt;/p&gt;</comment>
                            <comment id="77337" author="rstam" created="Tue, 3 Jan 2012 22:09:18 +0000"  >&lt;p&gt;See the comments above. BsonDateTime no longer has a DateTime value field, only a millisecondsSinceEpoch field. In addition, instead of providing a way to convert all DateTime values to local (not possible since BsonDateTime is by definition in UTC) we are providing two new properties that let you extract the value as a .NET DateTime in either local or UTC time (see AsLocalTime and AsUniversalTime).&lt;/p&gt;</comment>
                            <comment id="77262" author="rstam" created="Tue, 3 Jan 2012 18:36:48 +0000"  >&lt;p&gt;Thanks for the feedback. I agree. And anyway, once I remove the redundant DateTime field there would be no way convert to local time anyway. So the conversion will happen when you access the new ToLocalDateTime propery.&lt;/p&gt;</comment>
                            <comment id="77256" author="craiggwilson" created="Tue, 3 Jan 2012 18:11:27 +0000"  >&lt;p&gt;Sounds good.  My opinion here is as follows:&lt;/p&gt;

&lt;p&gt;Forget converting the entire document into local vs. utc time.  I like your last proposal where you simply have two properties, one for local and one for Universal.  The implicit conversion to DataTime should be in utc time.  So, if a developer wants local time, they can access the AsLocal property.  Otherwise, they get Utc.  I think that is sufficient.  &lt;/p&gt;</comment>
                            <comment id="76736" author="rstam" created="Fri, 30 Dec 2011 04:42:59 +0000"  >&lt;p&gt;I&apos;m actually considering changing the implementation of the BsonDateTime class so that it only has the long millisecondsSinceEpoch field (removing the DateTime value field).&lt;/p&gt;

&lt;p&gt;The original rational for having both fields was that a .NET DateTime has higher resolution than a BSON DateTime, and I didn&apos;t want to lose the extra resolution prematurely. Once we serialized and deserialized a BsonDateTime it could no longer be helped since the serialized form determines the resolution.&lt;/p&gt;

&lt;p&gt;My current thinking is that this is just misleading. Better to lose the resolution the instant you create an instance of BsonDateTime, and avoid creating the illusion that a BsonDateTime might have higher resolution than it actually does.&lt;/p&gt;

&lt;p&gt;Another rational for keeping the DateTime around with its higher resolution was that the ultimate serialized resolution might depend on the external format used. While binary BSON might be limited to millisecond resolution, a JSON file where DateTimes were serialized as ISODate string constants could conceivably maintain the full .NET resolution.&lt;/p&gt;

&lt;p&gt;Once again, this is misleading, and it is probably better for a BSON DateTime to have the same resolution no matter where it resides, be that in memory, in a binary BSON document or in a text based JSON document.&lt;/p&gt;

&lt;p&gt;As for the timezone question, an alternative proposal would be to provide alternative properties that could be used to convert millisecondsSinceEpoch (which by definition is in UTC) to either a local or a UTC DateTime. For example:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var bsonDateTime =  new BsonDateTime(DateTime.UtcNow);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var localTime = bsonDateTime.AsLocalDateTime;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;var utcTime = bsonDateTime.AsUniversalDateTime;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;Any comments?&lt;/p&gt;</comment>
                            <comment id="73238" author="craiggwilson" created="Thu, 15 Dec 2011 02:25:02 +0000"  >&lt;p&gt;BsonDateTime always represents times in utc. Do you see this change going down to that level to allow for BsonDateTime to have a local vs. utc component?&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10011">
                    <name>Depends</name>
                                            <outwardlinks description="depends on">
                                        <issuelink>
            <issuekey id="50144">CSHARP-567</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10011"><![CDATA[Minor Change]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrh87b:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14128</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>