mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 09:56:44 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			20 lines
		
	
	
		
			417 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			20 lines
		
	
	
		
			417 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 'use strict';
 | |
| 
 | |
| const dateFns = require('date-fns');
 | |
| 
 | |
| const { parseDateTimeOrTimestamp } = require('./shared/parsers');
 | |
| const Field = require('./field');
 | |
| 
 | |
| class TimestampField extends Field {
 | |
|   toDB(value) {
 | |
|     return parseDateTimeOrTimestamp(value);
 | |
|   }
 | |
| 
 | |
|   fromDB(value) {
 | |
|     const cast = new Date(value);
 | |
|     return dateFns.isValid(cast) ? dateFns.format(cast, 'T') : null;
 | |
|   }
 | |
| }
 | |
| 
 | |
| module.exports = TimestampField;
 | 
