npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@candourits/be-timezone-converter

v1.0.7

Published

candour backend middleware for automatic timezone conversion

Readme

Candour Backend Timezone Converter

A TypeScript library for automatically converting UTC dates to user timezones in Express API responses.

Features

  • ✅ Automatic conversion of dates in API responses to user's timezone
  • ✅ Preserves Express response chainability (res.status().json())
  • ✅ Type-safe with TypeScript support
  • ✅ Configurable date detection and field skipping
  • ✅ Works with any database ORM (Sequelize, TypeORM, etc.)
  • ✅ Zero changes needed in your controllers or models
  • ✅ Lightweight, with minimal dependencies

Installation

npm install @candour/be-timezone-converter

Quick Start

import express from 'express';
import { createTimezoneConverter } from '@candour/be-timezone-converter';

const app = express();
const { timezoneMiddleware, responseTransformerMiddleware } = createTimezoneConverter();

// Apply middleware
app.use(timezoneMiddleware);
app.use(responseTransformerMiddleware);

// Your routes
app.get('/api/data', (req, res) => {
  const data = [
    { id: 1, name: 'Item 1', createdAt: new Date() }
  ];
  
  // Dates will be automatically converted to user's timezone
  res.status(200).json(data);
});

app.listen(3000);

How It Works

  1. The timezoneMiddleware extracts the user's timezone from:

    • Query parameter: ?timezone=America/New_York
    • Request header: x-timezone: America/New_York
  2. The responseTransformerMiddleware automatically converts all UTC dates in your response to the user's timezone.

  3. All database operations continue to use UTC timestamps for consistency.

Configuration Options

const timezoneConverter = createTimezoneConverter({
  // Default timezone if none specified (default: 'UTC')
  defaultTimezone: 'America/New_York',
  
  // Custom header name (default: 'x-timezone')
  timezoneHeader: 'x-user-timezone',

  // Custom query parameter name (default: 'timezone')
  timezoneParam: 'tz',
  
  // Fields to skip during conversion
  skipFields: [
    'metadata',           // Skip the entire metadata object
    'config.*',           // Skip all properties inside config
    'rawTimestamps'       // Skip specific field
  ],

  // overrides other options and automatically detect user timezone based on the ip address and default to UTC if timezone is not found
  detectTimezone:true,
  
  // Custom function to determine if a value is a date
  dateDetector: (value) => {
    // Your custom detection logic
    return value instanceof Date || 
           (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}/.test(value));
  }
});

Manual Conversion

For cases where you need to manually convert dates:

const { convertDate, transformData } = createTimezoneConverter();

// Convert a single date
app.get('/api/time', (req, res) => {
  const now = new Date();
  const localTime = convertDate(now, req.userTimezone);
  
  res.json({ localTime });
});

// Transform a complex object
app.get('/api/custom', (req, res) => {
  const data = {
    user: {
      registeredAt: new Date(),
      lastLogin: new Date()
    }
  };
  
  const transformed = transformData(data, req.userTimezone);
  res.json(transformed);
});

TypeScript Support

The library includes type definitions and extends Express's Request interface:

import { Request, Response } from 'express';

app.get('/api/example', (req: Request, res: Response) => {
  // req.userTimezone is available and typed
  console.log(req.userTimezone); // e.g., 'America/New_York'
});

License

MIT