Is it possible for Prisma to generate a date in a timezone that is not UTC?

Currently, I am working on a webpage using Next.js to manage inventory tracking. To connect to my MySQL database, I rely on Prisma. One of the key features I want is the ability to create a new row in the database whenever there's a change in the inventory. This new entry should include the date and time when the change occurred. However, the issue I'm facing is that the generated date follows UTC+00:00, but what I actually need is for it to be based on UTC-06:00.

Here is the schema model representation in Prisma:

model inventory_movements {
  moveNumber    Int       @id @default(autoincrement())
  name          String    @db.VarChar(128)
  date          DateTime? @default(now()) @db.DateTime(0)
  amount        Decimal   @db.Decimal(11, 2)
  comment       String?   @db.VarChar(128)
}

My current approach involves using Moment.js to generate the date and then adjusting the timezone as required:

import moment from 'moment';
import 'moment-timezone';

prisma.inventory.create({
  data: {
    name: "product_name",
    amount: 1,
    comment: "comment on the change",
    date: moment().tz('America/Monterrey').format()
  }
});

The date output I get is ''2022-12-11T00:21:29-06:00'', whereas the database stores a different value ''2022-12-11 06:21:28''.

I attempted an alternative method where the database handles the date generation automatically with a default value set as NOW(), which worked correctly:

Therefore, I removed the date field from the Prisma command like so:

import moment from 'moment';
import 'moment-timezone';

prisma.inventory_movements.create({
  data: {
    name: "product_name",
    amount: 1,
    comment: "comment on the change",
  }
});

Unfortunately, this resulted in an error:

error - unhandledRejection: PrismaClientValidationError:
Invalid `prisma.inventory_movements.create()` invocation:

{
  data: {
    name: 'product_name',
    amount: '1',
    comment: 'comment on the change',
+   date: DateTime
  }
}

Note: Lines with + are required

Answer №1

It's effective in my case.

import moment from 'moment'
import timezone from 'moment-timezone'

yy.initialize({
  info: {
    timestamp: moment().tz('America/New_York').format()
  }
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm interested in clicking on an image within a div to trigger a page refresh and then automatically hide the div once the page has refreshed

UPDATE 2 SITUATION To prevent access to quiz content until the page is refreshed, I am employing a semi-transparent image with a top-margin off-set. The following code functions flawlessly on one specific page and only once: JavaScript window.addEventL ...

Changing the URL locale using Next.js router.push is unsuccessful

I am attempting to switch the locale by connecting the onClick event to two separate <div> elements: import { useRouter } from 'next/router' // other codes const router = useRouter() const changeLocale = (locale) => { router.push({ ...

Bringing in Contacts

Looking to organize users' imported contacts, like an address book. Currently, the table structure is as follows: imported_contacts: id, user_id, email, etc.... Considering creating two tables - one for imported contacts id, email, etc... and another ...

Encountered an AxiosError while handling a request with an HTTP status code of 404, in a stack involving Node.js, Express,

Attempting to integrate a registration and login system into my website using Axios to perform a post request in React (Home.jsx) to my Express server file (database.js), where information is retrieved from a MySQL database. However, upon submitting the in ...

Using the v-for directive to loop through a list of items and adding a v-autocomplete with

I am facing a challenge with using a dropdown menu within a loop to select the region for each office in my list of offices. The problem lies in passing the index value to the updateRegion method so that I can correctly associate the selected region with t ...

Is there a way to retrieve the value of elements that are deeply nested within multiple objects and arrays?

When making an API call to retrieve data from the Google Distance Matrix API, I store that information in my Redux store within a React application. The returned data object is structured as follows: Object { "destination_addresses": Array [ "21 Fo ...

Encountering issues when trying to build a Nestjs app with node-crc (rust cargo) in Docker

I am encountering an issue with building my Nest.js app using Docker due to a dependency called "node-crc" version "2.0.13" that fails during the docker build process. Here is my Dockerfile: FROM node:17.3.1-alpine RUN curl https://sh.rustup.rs -sSf | sh ...

React component fails to run within a foreach iteration

function displayCourses(props) { props.courses.forEach(course => { return <Header name={course.name} />; }); ... } The provided code is not properly rendering the Header component. By modifying the loop to course => console.log(cours ...

Seamless Exploration with Google StreetView

Google uses a special effect on StreetView images to transition smoothly between them. You can see an example of this effect in the images below, with the second image showing it being applied. My question is: How can I incorporate this same effect into m ...

When Laravel joins a query with an empty result set

I'm struggling to retrieve a list of jobs that don't have any tasks assigned to them, but I can't seem to figure it out. $jobs = Job::select( 'jobs.*' ) ->where( 'is_active', '=', 1 ) ->join( &apos ...

Tips for connecting a webpage element with endless scrolling functionality

Currently, I am dealing with a webpage that features a container utilizing infinite scroll to load numerous articles. I am faced with the challenge of how to effectively link to a particular article when its corresponding div is only loaded into the DOM u ...

Create a customized bracelet with a specified number of colors in JavaScript

I encountered an interesting challenge recently. The task was to create a bracelet of length n using a set of specified colors, following certain conditions: No two adjacent beads should have the same color (e.g., R R). A pattern of three consecutive bea ...

adding numerous items to an array using JavaScript

How can I add multiple objects to an array all at once? router.post(`/products`, upload.array("photos" , 10), async (req, res) => { console.log(res); try { let product = new Product(); req.files.forEach(file => { product.p ...

Create an additional data field in an existing resource using the PUT method

Incorporated Google authentication into my NextJS application. The process involves the user making progress within the web app, which is stored in local storage as an array. If the user decides to register, I receive the session back and then send a PUT r ...

Can a specific element be chosen based on its background color?

Is it possible to change the background color of a child element within a div that has a specific background color using CSS? See my explanation below. For example: .container[background-color=some color] .content { background-color: some other color ...

Display a div on page scroll using jQuery

Check out this snippet of HTML code I have: HTML <div id="box1"></div> <div id="box2"></div> <div id="box3"></div> <div id="box4"></div> <div id="box5"></div> And here's a segment of C ...

The relative link feature in React Router fails to properly navigate

Currently, I am utilizing the npm package react-router-relative (https://www.npmjs.com/package/react-router-relative) for my project. However, it seems to be having trouble properly switching the URL. Here is how my links are configured: <Link to=&apo ...

After 30 seconds of inactivity, apply the CSS once, then remove it before repeating the process

I've got a unique little CodePen with an animation that I want to execute only if the user hasn't clicked on the <div class="someDiv"> for 30 seconds. My question is, can someone guide me in the right direction so that when someone doesn&a ...

Can someone explain why my button icons are not aligning to the center properly?

I have a small issue with the icons I pulled from react-icons - they appear slightly raised within the buttons. How can I position them in the middle? That's my only query, but I can't post it alone due to mostly having code in my post. What an ...

Seamless menu display and collapse with a smooth transition

I'm interested in creating a smooth transition using tailwincss for the 'active' state change when showing or collapsing the menu. Although I attempted to add it during the state change by including transition delay-150 duration-300 ease-in ...