UTC formatted string time to local time in Word - ms-word

I have a Document Property that stores a DateTime in the UTC format.
For example:
2017-08-23T11:42:55.1094139Z
Now I would like to display this DateTime in my Word Document, there for I use the following field:
{ DOCPROPERTY LAST_UPDATED }
(FYI: LAST_UPDATED isnt the DateTime the file was last modified, but the last time the user clicked a sync button of my addin)
This will display the string as is, so in the UTC format.
I hoped that the following, would turn the UTC into the local DateTime.
{ DOCPROPERTY LAST_UPDATED \# "dd.MM.yyyy HH:mm:ss" }
but sadly, it ignores the CurrentCulture/LocalTimeZone completly and just displays it as
23.08.2017 11:42:55
Instead of the desired
23.08.2017 13:42:55
How can I achieve my goal? Store a DateTime in my Word Document that is independet of Region/TimeZones and let it display the local time?

Related

FieldValue.serverTimestamp() sets a timestamp in inconsistent format

My problem is that the format FieldValue.serverTimestamp() sets is inconsistent. On 'add' it's a string and on 'update' it's a DateTime.
With:
FirebaseFirestore.instance.collection('collectionName').add(
{'lastEdited': FieldValue.serverTimestamp()},
)
It sets the date as (string):
With:
FirebaseFirestore.instance.collection('collectionName').doc('id').update(
{'lastEdited': FieldValue.serverTimestamp()},
)
It updates as a DateTime (this format would be preferable):
Because of this, some of the documents have a date that is string and some that is DateTime. This causes orderBy('lastEdited') to not work. Please do let me know if you have some insight to this behaviour. Thanks.

DateRangePicker - Grey out unavailable dates

As the title suggests I am using DateRangePicker to add date ranges to an array. If possible I would like to be able to "grey" out already selected dates in the array. Is there anyway to do this?
Here is the solution to returning the dates in-between the range in case anyone else needs it.
List<DateTime> getDaysInBetweenIncludingStartEndDate(
{required DateTime startDateTime, required DateTime endDateTime}) {
// Converting dates provided to UTC
// So that all things like DST don't affect subtraction and addition on dates
DateTime startDateInUTC =
DateTime.utc(startDateTime.year, startDateTime.month, startDateTime.day);
DateTime endDateInUTC =
DateTime.utc(endDateTime.year, endDateTime.month, endDateTime.day);
// Created a list to hold all dates
List<DateTime> daysInFormat = [];
// Starting a loop with the initial value as the Start Date
// With an increment of 1 day on each loop
// With condition current value of loop is smaller than or same as end date
for (DateTime i = startDateInUTC;
i.isBefore(endDateInUTC) || i.isAtSameMomentAs(endDateInUTC);
i = i.add(const Duration(days: 1))) {
// Converting back UTC date to Local date if it was local before
// Or keeping in UTC format if it was UTC
if (startDateTime.isUtc) {
daysInFormat.add(i);
} else {
daysInFormat.add(DateTime(i.year, i.month, i.day));
}
}
return daysInFormat;
}
Yes, you can send disabled dates into the component.
Check this sample of the documentation.
For further options, check the whole docs.

Converting from 'H:mm a' format back to DateTime can't be parsed

const date = DateTime.fromISO('2022-03-27T08:50').toFormat('H:mm a') // 08:50 AM
console.log(DateTime.fromISO(date))
If I attempt the above, in the console log I get this explanation in the 'invalid' field:
explanation: "the input "8:30 AM" can't be parsed as ISO 8601"
reason: "unparsable"
Is it not possible to revert the string back to a date?
You can parse back "8:30 AM" as DateTime using fromFormat:
Create a DateTime from an input string and format string. Defaults to en-US if no locale has been specified, regardless of the system's locale. For a table of tokens and their interpretations, see here.
but the information about year, month and day are lost and so the new DateTime will default to the current day.
Example:
const DateTime = luxon.DateTime;
const date = DateTime.fromISO('2022-03-27T08:50').toFormat('H:mm a') // 8:50 AM
console.log(DateTime.fromFormat(date, 'h:mm a').toISO())
<script src="https://cdn.jsdelivr.net/npm/luxon#2.3.1/build/global/luxon.min.js"></script>

Save a birthDate via qraphql in postgres

I would like to save a birthdate from an (react) input (type = 'date'), send it via GraphQL to node backend and persist it in postgres in a date format.
Input in HTML: 09.07.2000
In GraphQL resolver: 2000-07-09T00:00:00.000Z
Date format in Postgres (original output in console): 09.07.2000
Well, that's what i expected. But now, if i request the same field:
Date format in Postgres (original output in console): 09.07.2000
Graphql response: 08.07.2000
HTML Input: 08.07.2000
If I change the scalar in graphQl schema to String, the following string returns: Fri Jul 09 2000 00:00:00 GMT+0200 (CEST)
Code
schema
scalar Date
type Child {
...
birthDate: Date
...
}
resolvers
const { GraphQLDate } = require('graphql-iso-date')
...
Date: GraphQLDate,
Problem
It looks like there is a problem in converting the date format from different timezones. If there is no timezone the scalar resolver guess a timezone. But this is a birthdate, it hast to be the same date on every timezone. How can I fix this? Do I have to use a string instead of date in prostgres?
Thanks for any support 🙏 I'm really lost
UPDATE
It looks like knex.js is the problem.
A normal SQL query responds the expected date. But a query with knex.js response a datetime.

How to assign current date to a date field in odoo 10

How to show current date before clicking the date field in odoo?
Odoo Date field class provides methods to get default values for like today.
For dates the method is called context_today() and for datetimes context_timestamp(). You are able to pass a timestamp to this methods to either get today/now (without timestamp) or a timestamp which will be formed by the logged in users timezone.
Code Example:
from odoo import fields, models
class MyModel(models.Model):
_name = 'my.model'
def _default_my_date(self):
return fields.Date.context_today(self)
my_date = fields.Date(string='My Date', default=_default_my_date)
Or the lambda version:
my_date = fields.Date(
string='My Date', default=lambda s: fields.Date.context_today(s))
I found it.It is Simple, just write this on your python code like:
date = fields.Datetime(string="Date", default=lambda *a: datetime.now(),required=True)
or
like this
date = fields.Datetime(string="Date current action", default=lambda *a: datetime.now())
or
like this
date = fields.Date(default=fields.Date.today)