Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hortau/react-native-device-time-format

Package Overview
Dependencies
Maintainers
4
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hortau/react-native-device-time-format

Get device setting for time format in react-native

  • 2.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

react-native-device-time-format

On mobile devices users have the option to opt in/out, of the systems locale, in regards to 12/24 hour clock format:

12/24 time format iOS settings

This package exposes this device setting for iOS & Android.

Contributions

This package was heavily inspired by react-native-device-clock-format, which is "no longer actively maintained", and only supports iOS.

  • React Native: 0.60+ autolinking support - fix by Tim Kuilman
  • Android: SDK Build Tools version warning - fix by Tihomir Valkanov

Thank you 🙏

Getting started

Install with your preferred package manager:

yarn add react-native-device-time-format

or

npm install react-native-device-time-format --save &&

For iOS, install pod:

(cd ios/ && pod install)

For React Native < 0.60, run:

react-native link react-native-device-time-format

Should the automatic linking fail (in case of folder structure mismatch or various other reasons), please follow the manual installation guide.

Usage

Bellow is an example of fetching the hours & minutes string representation from a date, with the device time format (using moment for date/time formatting):

import { is24HourFormat } from '@hortau/react-native-device-time-format'
import moment from 'moment'

/**
 * @function getCurrentHourFormat
 * @param  {Date} date Date to format
 * @return {Promise<string>} formatted string HH:mm / h:mm A, depending on device setting
 */
const getCurrentHourFormat = async (date) => {
  const is24Hour = await is24HourFormat()
  return moment(date).format(is24Hour ? 'HH:mm' : 'h:mm A'))
}

All native modules runs asynchronous, I would suggest updating an internal state in your app when AppState changes to active.

Keywords

FAQs

Package last updated on 20 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc